
USE [GiftShop]
GO

/****** Object:  StoredProcedure [proc_AttachedFilesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AttachedFilesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AttachedFilesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_AttachedFilesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Category],
		[OwnerObjectID],
		[FileName],
		[Path],
		[CreatedDate],
		[Deleted]
	FROM [AttachedFiles]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AttachedFilesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_AttachedFilesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_AttachedFilesLoadAll]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AttachedFilesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AttachedFilesLoadAll];
GO

CREATE PROCEDURE [proc_AttachedFilesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Category],
		[OwnerObjectID],
		[FileName],
		[Path],
		[CreatedDate],
		[Deleted]
	FROM [AttachedFiles]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AttachedFilesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_AttachedFilesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_AttachedFilesUpdate]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AttachedFilesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AttachedFilesUpdate];
GO

CREATE PROCEDURE [proc_AttachedFilesUpdate]
(
	@ID int,
	@Category int = NULL,
	@OwnerObjectID int,
	@FileName nvarchar(200) = NULL,
	@Path nvarchar(500) = NULL,
	@CreatedDate datetime = NULL,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [AttachedFiles]
	SET
		[Category] = @Category,
		[OwnerObjectID] = @OwnerObjectID,
		[FileName] = @FileName,
		[Path] = @Path,
		[CreatedDate] = @CreatedDate,
		[Deleted] = @Deleted
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AttachedFilesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_AttachedFilesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_AttachedFilesInsert]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AttachedFilesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AttachedFilesInsert];
GO

CREATE PROCEDURE [proc_AttachedFilesInsert]
(
	@ID int = NULL output,
	@Category int = NULL,
	@OwnerObjectID int,
	@FileName nvarchar(200) = NULL,
	@Path nvarchar(500) = NULL,
	@CreatedDate datetime = NULL,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [AttachedFiles]
	(
		[Category],
		[OwnerObjectID],
		[FileName],
		[Path],
		[CreatedDate],
		[Deleted]
	)
	VALUES
	(
		@Category,
		@OwnerObjectID,
		@FileName,
		@Path,
		@CreatedDate,
		@Deleted
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AttachedFilesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_AttachedFilesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_AttachedFilesDelete]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_AttachedFilesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_AttachedFilesDelete];
GO

CREATE PROCEDURE [proc_AttachedFilesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [AttachedFiles]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_AttachedFilesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_AttachedFilesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BannersLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BannersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BannersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_BannersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FileName],
		[Description],
		[Deleted],
		[LastModifiedDate],
		[URL],
		[PageID]
	FROM [Banners]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BannersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_BannersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BannersLoadAll]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BannersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BannersLoadAll];
GO

CREATE PROCEDURE [proc_BannersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FileName],
		[Description],
		[Deleted],
		[LastModifiedDate],
		[URL],
		[PageID]
	FROM [Banners]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BannersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_BannersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BannersUpdate]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BannersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BannersUpdate];
GO

CREATE PROCEDURE [proc_BannersUpdate]
(
	@ID int,
	@FileName nvarchar(500) = NULL,
	@Description nvarchar(500) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@URL nvarchar(500) = NULL,
	@PageID int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Banners]
	SET
		[FileName] = @FileName,
		[Description] = @Description,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[URL] = @URL,
		[PageID] = @PageID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BannersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_BannersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_BannersInsert]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BannersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BannersInsert];
GO

CREATE PROCEDURE [proc_BannersInsert]
(
	@ID int = NULL output,
	@FileName nvarchar(500) = NULL,
	@Description nvarchar(500) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@URL nvarchar(500) = NULL,
	@PageID int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Banners]
	(
		[FileName],
		[Description],
		[Deleted],
		[LastModifiedDate],
		[URL],
		[PageID]
	)
	VALUES
	(
		@FileName,
		@Description,
		@Deleted,
		@LastModifiedDate,
		@URL,
		@PageID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BannersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_BannersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BannersDelete]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BannersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BannersDelete];
GO

CREATE PROCEDURE [proc_BannersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Banners]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BannersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_BannersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BranchesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_BranchesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Name],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Address],
		[ABN],
		[Phone],
		[Fax],
		[IsHeadQuarter],
		[Active],
		[Deleted]
	FROM [Branches]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BranchesLoadAll]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchesLoadAll];
GO

CREATE PROCEDURE [proc_BranchesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Name],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Address],
		[ABN],
		[Phone],
		[Fax],
		[IsHeadQuarter],
		[Active],
		[Deleted]
	FROM [Branches]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BranchesUpdate]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchesUpdate];
GO

CREATE PROCEDURE [proc_BranchesUpdate]
(
	@ID int,
	@Name nvarchar(200),
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Address nvarchar(500) = NULL,
	@ABN nvarchar(50) = NULL,
	@Phone nvarchar(50) = NULL,
	@Fax nvarchar(50) = NULL,
	@IsHeadQuarter bit,
	@Active bit,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Branches]
	SET
		[Name] = @Name,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Address] = @Address,
		[ABN] = @ABN,
		[Phone] = @Phone,
		[Fax] = @Fax,
		[IsHeadQuarter] = @IsHeadQuarter,
		[Active] = @Active,
		[Deleted] = @Deleted
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_BranchesInsert]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchesInsert];
GO

CREATE PROCEDURE [proc_BranchesInsert]
(
	@ID int = NULL output,
	@Name nvarchar(200),
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Address nvarchar(500) = NULL,
	@ABN nvarchar(50) = NULL,
	@Phone nvarchar(50) = NULL,
	@Fax nvarchar(50) = NULL,
	@IsHeadQuarter bit,
	@Active bit,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Branches]
	(
		[Name],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Address],
		[ABN],
		[Phone],
		[Fax],
		[IsHeadQuarter],
		[Active],
		[Deleted]
	)
	VALUES
	(
		@Name,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Address,
		@ABN,
		@Phone,
		@Fax,
		@IsHeadQuarter,
		@Active,
		@Deleted
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BranchesDelete]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchesDelete];
GO

CREATE PROCEDURE [proc_BranchesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Branches]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BranchRoleLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchRoleLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchRoleLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_BranchRoleLoadByPrimaryKey]
(
	@BranchID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Products],
		[Sales],
		[Purchase],
		[Customers],
		[Suppliers],
		[Repair],
		[Report],
		[Admin],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Contracts],
		[BranchID],
		[SystemAdmin],
		[EditSales],
		[Expense]
	FROM [BranchRole]
	WHERE
		([BranchID] = @BranchID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchRoleLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchRoleLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BranchRoleLoadAll]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchRoleLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchRoleLoadAll];
GO

CREATE PROCEDURE [proc_BranchRoleLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Products],
		[Sales],
		[Purchase],
		[Customers],
		[Suppliers],
		[Repair],
		[Report],
		[Admin],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Contracts],
		[BranchID],
		[SystemAdmin],
		[EditSales],
		[Expense]
	FROM [BranchRole]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchRoleLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchRoleLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BranchRoleUpdate]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchRoleUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchRoleUpdate];
GO

CREATE PROCEDURE [proc_BranchRoleUpdate]
(
	@Products bit,
	@Sales bit,
	@Purchase bit,
	@Customers bit,
	@Suppliers bit,
	@Repair bit,
	@Report bit,
	@Admin bit,
	@LastModifiedDate datetime,
	@LastModifiedByUser int,
	@Contracts bit,
	@BranchID int,
	@SystemAdmin bit,
	@EditSales bit,
	@Expense bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [BranchRole]
	SET
		[Products] = @Products,
		[Sales] = @Sales,
		[Purchase] = @Purchase,
		[Customers] = @Customers,
		[Suppliers] = @Suppliers,
		[Repair] = @Repair,
		[Report] = @Report,
		[Admin] = @Admin,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Contracts] = @Contracts,
		[SystemAdmin] = @SystemAdmin,
		[EditSales] = @EditSales,
		[Expense] = @Expense
	WHERE
		[BranchID] = @BranchID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchRoleUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchRoleUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_BranchRoleInsert]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchRoleInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchRoleInsert];
GO

CREATE PROCEDURE [proc_BranchRoleInsert]
(
	@Products bit,
	@Sales bit,
	@Purchase bit,
	@Customers bit,
	@Suppliers bit,
	@Repair bit,
	@Report bit,
	@Admin bit,
	@LastModifiedDate datetime,
	@LastModifiedByUser int,
	@Contracts bit,
	@BranchID int,
	@SystemAdmin bit,
	@EditSales bit,
	@Expense bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [BranchRole]
	(
		[Products],
		[Sales],
		[Purchase],
		[Customers],
		[Suppliers],
		[Repair],
		[Report],
		[Admin],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Contracts],
		[BranchID],
		[SystemAdmin],
		[EditSales],
		[Expense]
	)
	VALUES
	(
		@Products,
		@Sales,
		@Purchase,
		@Customers,
		@Suppliers,
		@Repair,
		@Report,
		@Admin,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Contracts,
		@BranchID,
		@SystemAdmin,
		@EditSales,
		@Expense
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchRoleInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchRoleInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BranchRoleDelete]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BranchRoleDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BranchRoleDelete];
GO

CREATE PROCEDURE [proc_BranchRoleDelete]
(
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [BranchRole]
	WHERE
		[BranchID] = @BranchID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BranchRoleDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_BranchRoleDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BrandsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BrandsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BrandsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_BrandsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[BrandName],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID],
		[StockKey]
	FROM [Brands]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BrandsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_BrandsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BrandsLoadAll]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BrandsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BrandsLoadAll];
GO

CREATE PROCEDURE [proc_BrandsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[BrandName],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID],
		[StockKey]
	FROM [Brands]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BrandsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_BrandsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BrandsUpdate]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BrandsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BrandsUpdate];
GO

CREATE PROCEDURE [proc_BrandsUpdate]
(
	@ID int,
	@BrandName nvarchar(50) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int,
	@StockKey int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Brands]
	SET
		[BrandName] = @BrandName,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[BranchID] = @BranchID,
		[StockKey] = @StockKey
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BrandsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_BrandsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_BrandsInsert]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BrandsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BrandsInsert];
GO

CREATE PROCEDURE [proc_BrandsInsert]
(
	@ID int = NULL output,
	@BrandName nvarchar(50) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int,
	@StockKey int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Brands]
	(
		[BrandName],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID],
		[StockKey]
	)
	VALUES
	(
		@BrandName,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@BranchID,
		@StockKey
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BrandsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_BrandsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BrandsDelete]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BrandsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BrandsDelete];
GO

CREATE PROCEDURE [proc_BrandsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Brands]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BrandsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_BrandsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BusinessCardsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BusinessCardsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BusinessCardsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_BusinessCardsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FrontSide],
		[BackSide],
		[Deleted],
		[CreatedDate],
		[Status],
		[CreatedByCustomer],
		[CreatedByAdmin]
	FROM [BusinessCards]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BusinessCardsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_BusinessCardsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BusinessCardsLoadAll]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BusinessCardsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BusinessCardsLoadAll];
GO

CREATE PROCEDURE [proc_BusinessCardsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FrontSide],
		[BackSide],
		[Deleted],
		[CreatedDate],
		[Status],
		[CreatedByCustomer],
		[CreatedByAdmin]
	FROM [BusinessCards]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BusinessCardsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_BusinessCardsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BusinessCardsUpdate]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BusinessCardsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BusinessCardsUpdate];
GO

CREATE PROCEDURE [proc_BusinessCardsUpdate]
(
	@ID int,
	@FrontSide nvarchar(MAX) = NULL,
	@BackSide nvarchar(MAX) = NULL,
	@Deleted bit,
	@CreatedDate datetime = NULL,
	@Status int = NULL,
	@CreatedByCustomer int = NULL,
	@CreatedByAdmin int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [BusinessCards]
	SET
		[FrontSide] = @FrontSide,
		[BackSide] = @BackSide,
		[Deleted] = @Deleted,
		[CreatedDate] = @CreatedDate,
		[Status] = @Status,
		[CreatedByCustomer] = @CreatedByCustomer,
		[CreatedByAdmin] = @CreatedByAdmin
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BusinessCardsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_BusinessCardsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_BusinessCardsInsert]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BusinessCardsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BusinessCardsInsert];
GO

CREATE PROCEDURE [proc_BusinessCardsInsert]
(
	@ID int = NULL output,
	@FrontSide nvarchar(MAX) = NULL,
	@BackSide nvarchar(MAX) = NULL,
	@Deleted bit,
	@CreatedDate datetime = NULL,
	@Status int = NULL,
	@CreatedByCustomer int = NULL,
	@CreatedByAdmin int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [BusinessCards]
	(
		[FrontSide],
		[BackSide],
		[Deleted],
		[CreatedDate],
		[Status],
		[CreatedByCustomer],
		[CreatedByAdmin]
	)
	VALUES
	(
		@FrontSide,
		@BackSide,
		@Deleted,
		@CreatedDate,
		@Status,
		@CreatedByCustomer,
		@CreatedByAdmin
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BusinessCardsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_BusinessCardsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_BusinessCardsDelete]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_BusinessCardsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_BusinessCardsDelete];
GO

CREATE PROCEDURE [proc_BusinessCardsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [BusinessCards]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_BusinessCardsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_BusinessCardsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CardPapersLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CardPapersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CardPapersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CardPapersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Name],
		[Description],
		[Deleted],
		[SampleImage]
	FROM [CardPapers]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CardPapersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_CardPapersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CardPapersLoadAll]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CardPapersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CardPapersLoadAll];
GO

CREATE PROCEDURE [proc_CardPapersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Name],
		[Description],
		[Deleted],
		[SampleImage]
	FROM [CardPapers]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CardPapersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_CardPapersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CardPapersUpdate]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CardPapersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CardPapersUpdate];
GO

CREATE PROCEDURE [proc_CardPapersUpdate]
(
	@ID int,
	@Name nvarchar(150) = NULL,
	@Description nvarchar(500) = NULL,
	@Deleted bit,
	@SampleImage nvarchar(500) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CardPapers]
	SET
		[Name] = @Name,
		[Description] = @Description,
		[Deleted] = @Deleted,
		[SampleImage] = @SampleImage
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CardPapersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_CardPapersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_CardPapersInsert]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CardPapersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CardPapersInsert];
GO

CREATE PROCEDURE [proc_CardPapersInsert]
(
	@ID int = NULL output,
	@Name nvarchar(150) = NULL,
	@Description nvarchar(500) = NULL,
	@Deleted bit,
	@SampleImage nvarchar(500) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CardPapers]
	(
		[Name],
		[Description],
		[Deleted],
		[SampleImage]
	)
	VALUES
	(
		@Name,
		@Description,
		@Deleted,
		@SampleImage
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CardPapersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_CardPapersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CardPapersDelete]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CardPapersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CardPapersDelete];
GO

CREATE PROCEDURE [proc_CardPapersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CardPapers]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CardPapersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_CardPapersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CategoriesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CategoriesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[CategoryName],
		[ParentID],
		[Level],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[IsDefault],
		[VisibleToCustomer],
		[IsDealerOnly],
		[BranchID],
		[StockKey]
	FROM [Categories]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CategoriesLoadAll]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesLoadAll];
GO

CREATE PROCEDURE [proc_CategoriesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[CategoryName],
		[ParentID],
		[Level],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[IsDefault],
		[VisibleToCustomer],
		[IsDealerOnly],
		[BranchID],
		[StockKey]
	FROM [Categories]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CategoriesUpdate]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesUpdate];
GO

CREATE PROCEDURE [proc_CategoriesUpdate]
(
	@ID int,
	@CategoryName nvarchar(50) = NULL,
	@ParentID int = NULL,
	@Level int = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@IsDefault bit = NULL,
	@VisibleToCustomer bit = NULL,
	@IsDealerOnly bit = NULL,
	@BranchID int,
	@StockKey int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Categories]
	SET
		[CategoryName] = @CategoryName,
		[ParentID] = @ParentID,
		[Level] = @Level,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[IsDefault] = @IsDefault,
		[VisibleToCustomer] = @VisibleToCustomer,
		[IsDealerOnly] = @IsDealerOnly,
		[BranchID] = @BranchID,
		[StockKey] = @StockKey
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_CategoriesInsert]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesInsert];
GO

CREATE PROCEDURE [proc_CategoriesInsert]
(
	@ID int = NULL output,
	@CategoryName nvarchar(50) = NULL,
	@ParentID int = NULL,
	@Level int = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@IsDefault bit = NULL,
	@VisibleToCustomer bit = NULL,
	@IsDealerOnly bit = NULL,
	@BranchID int,
	@StockKey int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Categories]
	(
		[CategoryName],
		[ParentID],
		[Level],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[IsDefault],
		[VisibleToCustomer],
		[IsDealerOnly],
		[BranchID],
		[StockKey]
	)
	VALUES
	(
		@CategoryName,
		@ParentID,
		@Level,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@IsDefault,
		@VisibleToCustomer,
		@IsDealerOnly,
		@BranchID,
		@StockKey
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CategoriesDelete]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CategoriesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CategoriesDelete];
GO

CREATE PROCEDURE [proc_CategoriesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Categories]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CategoriesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_CategoriesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ContractsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ContractsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ContractsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ContractsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ContractNo],
		[ProductDetailID],
		[Cost],
		[MobileNumber],
		[PlanDescription],
		[PlanDuration],
		[Commission],
		[Rebate],
		[MPP],
		[NetworkID],
		[InvoiceID],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[CreatedDate],
		[CreatedByUser],
		[Memo],
		[ContractCreatedDate],
		[ContractStartDate],
		[ContractEndDate],
		[BranchID]
	FROM [Contracts]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ContractsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ContractsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ContractsLoadAll]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ContractsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ContractsLoadAll];
GO

CREATE PROCEDURE [proc_ContractsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ContractNo],
		[ProductDetailID],
		[Cost],
		[MobileNumber],
		[PlanDescription],
		[PlanDuration],
		[Commission],
		[Rebate],
		[MPP],
		[NetworkID],
		[InvoiceID],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[CreatedDate],
		[CreatedByUser],
		[Memo],
		[ContractCreatedDate],
		[ContractStartDate],
		[ContractEndDate],
		[BranchID]
	FROM [Contracts]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ContractsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ContractsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ContractsUpdate]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ContractsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ContractsUpdate];
GO

CREATE PROCEDURE [proc_ContractsUpdate]
(
	@ID int,
	@ContractNo char(10) = NULL,
	@ProductDetailID int,
	@Cost numeric(18,2) = NULL,
	@MobileNumber nvarchar(20) = NULL,
	@PlanDescription nvarchar(100) = NULL,
	@PlanDuration tinyint = NULL,
	@Commission numeric(18,2) = NULL,
	@Rebate numeric(18,2) = NULL,
	@MPP numeric(18,2) = NULL,
	@NetworkID int,
	@InvoiceID int,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@CreatedDate datetime,
	@CreatedByUser int,
	@Memo nvarchar(MAX) = NULL,
	@ContractCreatedDate datetime,
	@ContractStartDate datetime = NULL,
	@ContractEndDate datetime = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Contracts]
	SET
		[ContractNo] = @ContractNo,
		[ProductDetailID] = @ProductDetailID,
		[Cost] = @Cost,
		[MobileNumber] = @MobileNumber,
		[PlanDescription] = @PlanDescription,
		[PlanDuration] = @PlanDuration,
		[Commission] = @Commission,
		[Rebate] = @Rebate,
		[MPP] = @MPP,
		[NetworkID] = @NetworkID,
		[InvoiceID] = @InvoiceID,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Deleted] = @Deleted,
		[CreatedDate] = @CreatedDate,
		[CreatedByUser] = @CreatedByUser,
		[Memo] = @Memo,
		[ContractCreatedDate] = @ContractCreatedDate,
		[ContractStartDate] = @ContractStartDate,
		[ContractEndDate] = @ContractEndDate,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ContractsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ContractsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ContractsInsert]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ContractsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ContractsInsert];
GO

CREATE PROCEDURE [proc_ContractsInsert]
(
	@ID int = NULL output,
	@ContractNo char(10) = NULL,
	@ProductDetailID int,
	@Cost numeric(18,2) = NULL,
	@MobileNumber nvarchar(20) = NULL,
	@PlanDescription nvarchar(100) = NULL,
	@PlanDuration tinyint = NULL,
	@Commission numeric(18,2) = NULL,
	@Rebate numeric(18,2) = NULL,
	@MPP numeric(18,2) = NULL,
	@NetworkID int,
	@InvoiceID int,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@CreatedDate datetime,
	@CreatedByUser int,
	@Memo nvarchar(MAX) = NULL,
	@ContractCreatedDate datetime,
	@ContractStartDate datetime = NULL,
	@ContractEndDate datetime = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Contracts]
	(
		[ContractNo],
		[ProductDetailID],
		[Cost],
		[MobileNumber],
		[PlanDescription],
		[PlanDuration],
		[Commission],
		[Rebate],
		[MPP],
		[NetworkID],
		[InvoiceID],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[CreatedDate],
		[CreatedByUser],
		[Memo],
		[ContractCreatedDate],
		[ContractStartDate],
		[ContractEndDate],
		[BranchID]
	)
	VALUES
	(
		@ContractNo,
		@ProductDetailID,
		@Cost,
		@MobileNumber,
		@PlanDescription,
		@PlanDuration,
		@Commission,
		@Rebate,
		@MPP,
		@NetworkID,
		@InvoiceID,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Deleted,
		@CreatedDate,
		@CreatedByUser,
		@Memo,
		@ContractCreatedDate,
		@ContractStartDate,
		@ContractEndDate,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ContractsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ContractsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ContractsDelete]    Script Date: 9/17/2011 5:25:57 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ContractsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ContractsDelete];
GO

CREATE PROCEDURE [proc_ContractsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Contracts]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ContractsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ContractsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerFeedbacksLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerFeedbacksLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerFeedbacksLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CustomerFeedbacksLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[CustomerName],
		[Content],
		[CreatedDate],
		[Deleted],
		[BranchID]
	FROM [CustomerFeedbacks]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerFeedbacksLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerFeedbacksLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerFeedbacksLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerFeedbacksLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerFeedbacksLoadAll];
GO

CREATE PROCEDURE [proc_CustomerFeedbacksLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[CustomerName],
		[Content],
		[CreatedDate],
		[Deleted],
		[BranchID]
	FROM [CustomerFeedbacks]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerFeedbacksLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerFeedbacksLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerFeedbacksUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerFeedbacksUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerFeedbacksUpdate];
GO

CREATE PROCEDURE [proc_CustomerFeedbacksUpdate]
(
	@ID int,
	@CustomerName nvarchar(50),
	@Content nvarchar(500),
	@CreatedDate datetime,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CustomerFeedbacks]
	SET
		[CustomerName] = @CustomerName,
		[Content] = @Content,
		[CreatedDate] = @CreatedDate,
		[Deleted] = @Deleted,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerFeedbacksUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerFeedbacksUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_CustomerFeedbacksInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerFeedbacksInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerFeedbacksInsert];
GO

CREATE PROCEDURE [proc_CustomerFeedbacksInsert]
(
	@ID int = NULL output,
	@CustomerName nvarchar(50),
	@Content nvarchar(500),
	@CreatedDate datetime,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CustomerFeedbacks]
	(
		[CustomerName],
		[Content],
		[CreatedDate],
		[Deleted],
		[BranchID]
	)
	VALUES
	(
		@CustomerName,
		@Content,
		@CreatedDate,
		@Deleted,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerFeedbacksInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerFeedbacksInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerFeedbacksDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerFeedbacksDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerFeedbacksDelete];
GO

CREATE PROCEDURE [proc_CustomerFeedbacksDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CustomerFeedbacks]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerFeedbacksDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerFeedbacksDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerOrdersLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CustomerOrdersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[OrderNo],
		[CustomerID],
		[CustomerAddress],
		[CustomerName],
		[CustomerPhone],
		[PreferredShipDate],
		[ShipAddress],
		[Note],
		[ShipDate],
		[PaymentMethodID],
		[TotalAmount],
		[GST],
		[StatusID],
		[InvoiceID],
		[Deleted],
		[CreatedDate],
		[LastModifiedDate],
		[LastModifiedByUser],
		[LastModifiedByCustomer],
		[BranchID],
		[VoucherID]
	FROM [CustomerOrders]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerOrdersLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersLoadAll];
GO

CREATE PROCEDURE [proc_CustomerOrdersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[OrderNo],
		[CustomerID],
		[CustomerAddress],
		[CustomerName],
		[CustomerPhone],
		[PreferredShipDate],
		[ShipAddress],
		[Note],
		[ShipDate],
		[PaymentMethodID],
		[TotalAmount],
		[GST],
		[StatusID],
		[InvoiceID],
		[Deleted],
		[CreatedDate],
		[LastModifiedDate],
		[LastModifiedByUser],
		[LastModifiedByCustomer],
		[BranchID],
		[VoucherID]
	FROM [CustomerOrders]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerOrdersUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersUpdate];
GO

CREATE PROCEDURE [proc_CustomerOrdersUpdate]
(
	@ID int,
	@OrderNo char(10),
	@CustomerID int = NULL,
	@CustomerAddress nvarchar(200) = NULL,
	@CustomerName nvarchar(50) = NULL,
	@CustomerPhone nvarchar(20) = NULL,
	@PreferredShipDate datetime = NULL,
	@ShipAddress nvarchar(200),
	@Note nvarchar(MAX) = NULL,
	@ShipDate datetime = NULL,
	@PaymentMethodID int = NULL,
	@TotalAmount numeric(18,2),
	@GST numeric(18,2),
	@StatusID int,
	@InvoiceID int = NULL,
	@Deleted bit,
	@CreatedDate datetime,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@LastModifiedByCustomer int = NULL,
	@BranchID int,
	@VoucherID uniqueidentifier = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CustomerOrders]
	SET
		[OrderNo] = @OrderNo,
		[CustomerID] = @CustomerID,
		[CustomerAddress] = @CustomerAddress,
		[CustomerName] = @CustomerName,
		[CustomerPhone] = @CustomerPhone,
		[PreferredShipDate] = @PreferredShipDate,
		[ShipAddress] = @ShipAddress,
		[Note] = @Note,
		[ShipDate] = @ShipDate,
		[PaymentMethodID] = @PaymentMethodID,
		[TotalAmount] = @TotalAmount,
		[GST] = @GST,
		[StatusID] = @StatusID,
		[InvoiceID] = @InvoiceID,
		[Deleted] = @Deleted,
		[CreatedDate] = @CreatedDate,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[LastModifiedByCustomer] = @LastModifiedByCustomer,
		[BranchID] = @BranchID,
		[VoucherID] = @VoucherID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_CustomerOrdersInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersInsert];
GO

CREATE PROCEDURE [proc_CustomerOrdersInsert]
(
	@ID int = NULL output,
	@OrderNo char(10),
	@CustomerID int = NULL,
	@CustomerAddress nvarchar(200) = NULL,
	@CustomerName nvarchar(50) = NULL,
	@CustomerPhone nvarchar(20) = NULL,
	@PreferredShipDate datetime = NULL,
	@ShipAddress nvarchar(200),
	@Note nvarchar(MAX) = NULL,
	@ShipDate datetime = NULL,
	@PaymentMethodID int = NULL,
	@TotalAmount numeric(18,2),
	@GST numeric(18,2),
	@StatusID int,
	@InvoiceID int = NULL,
	@Deleted bit,
	@CreatedDate datetime,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@LastModifiedByCustomer int = NULL,
	@BranchID int,
	@VoucherID uniqueidentifier = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CustomerOrders]
	(
		[OrderNo],
		[CustomerID],
		[CustomerAddress],
		[CustomerName],
		[CustomerPhone],
		[PreferredShipDate],
		[ShipAddress],
		[Note],
		[ShipDate],
		[PaymentMethodID],
		[TotalAmount],
		[GST],
		[StatusID],
		[InvoiceID],
		[Deleted],
		[CreatedDate],
		[LastModifiedDate],
		[LastModifiedByUser],
		[LastModifiedByCustomer],
		[BranchID],
		[VoucherID]
	)
	VALUES
	(
		@OrderNo,
		@CustomerID,
		@CustomerAddress,
		@CustomerName,
		@CustomerPhone,
		@PreferredShipDate,
		@ShipAddress,
		@Note,
		@ShipDate,
		@PaymentMethodID,
		@TotalAmount,
		@GST,
		@StatusID,
		@InvoiceID,
		@Deleted,
		@CreatedDate,
		@LastModifiedDate,
		@LastModifiedByUser,
		@LastModifiedByCustomer,
		@BranchID,
		@VoucherID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerOrdersDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerOrdersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerOrdersDelete];
GO

CREATE PROCEDURE [proc_CustomerOrdersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CustomerOrders]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerOrdersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerOrdersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerRequestsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerRequestsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerRequestsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CustomerRequestsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Title],
		[Content],
		[Requestor],
		[CreatedDate],
		[Deleted],
		[Email],
		[Address],
		[Important],
		[Unread],
		[BranchID]
	FROM [CustomerRequests]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerRequestsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerRequestsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerRequestsLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerRequestsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerRequestsLoadAll];
GO

CREATE PROCEDURE [proc_CustomerRequestsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Title],
		[Content],
		[Requestor],
		[CreatedDate],
		[Deleted],
		[Email],
		[Address],
		[Important],
		[Unread],
		[BranchID]
	FROM [CustomerRequests]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerRequestsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerRequestsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerRequestsUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerRequestsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerRequestsUpdate];
GO

CREATE PROCEDURE [proc_CustomerRequestsUpdate]
(
	@ID int,
	@Title nvarchar(200) = NULL,
	@Content ntext = NULL,
	@Requestor nvarchar(50) = NULL,
	@CreatedDate datetime = NULL,
	@Deleted bit,
	@Email nvarchar(50) = NULL,
	@Address nvarchar(100) = NULL,
	@Important bit = NULL,
	@Unread bit = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CustomerRequests]
	SET
		[Title] = @Title,
		[Content] = @Content,
		[Requestor] = @Requestor,
		[CreatedDate] = @CreatedDate,
		[Deleted] = @Deleted,
		[Email] = @Email,
		[Address] = @Address,
		[Important] = @Important,
		[Unread] = @Unread,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerRequestsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerRequestsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_CustomerRequestsInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerRequestsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerRequestsInsert];
GO

CREATE PROCEDURE [proc_CustomerRequestsInsert]
(
	@ID int = NULL output,
	@Title nvarchar(200) = NULL,
	@Content ntext = NULL,
	@Requestor nvarchar(50) = NULL,
	@CreatedDate datetime = NULL,
	@Deleted bit,
	@Email nvarchar(50) = NULL,
	@Address nvarchar(100) = NULL,
	@Important bit = NULL,
	@Unread bit = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CustomerRequests]
	(
		[Title],
		[Content],
		[Requestor],
		[CreatedDate],
		[Deleted],
		[Email],
		[Address],
		[Important],
		[Unread],
		[BranchID]
	)
	VALUES
	(
		@Title,
		@Content,
		@Requestor,
		@CreatedDate,
		@Deleted,
		@Email,
		@Address,
		@Important,
		@Unread,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerRequestsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerRequestsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerRequestsDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerRequestsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerRequestsDelete];
GO

CREATE PROCEDURE [proc_CustomerRequestsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CustomerRequests]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerRequestsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerRequestsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomersLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CustomersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[CustomerName],
		[Company],
		[Address],
		[Phone],
		[Fax],
		[Mobile],
		[Email],
		[Password],
		[CustomerType],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[TotalAmount],
		[PaidAmount],
		[CreditLine],
		[BranchID]
	FROM [Customers]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomersLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomersLoadAll];
GO

CREATE PROCEDURE [proc_CustomersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[CustomerName],
		[Company],
		[Address],
		[Phone],
		[Fax],
		[Mobile],
		[Email],
		[Password],
		[CustomerType],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[TotalAmount],
		[PaidAmount],
		[CreditLine],
		[BranchID]
	FROM [Customers]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomersUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomersUpdate];
GO

CREATE PROCEDURE [proc_CustomersUpdate]
(
	@ID int,
	@CustomerName nvarchar(50) = NULL,
	@Company nvarchar(50) = NULL,
	@Address nvarchar(100) = NULL,
	@Phone nvarchar(20) = NULL,
	@Fax nvarchar(20) = NULL,
	@Mobile nvarchar(20) = NULL,
	@Email nvarchar(50) = NULL,
	@Password nvarchar(50) = NULL,
	@CustomerType int = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@TotalAmount numeric(18,2) = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@CreditLine numeric(18,2) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Customers]
	SET
		[CustomerName] = @CustomerName,
		[Company] = @Company,
		[Address] = @Address,
		[Phone] = @Phone,
		[Fax] = @Fax,
		[Mobile] = @Mobile,
		[Email] = @Email,
		[Password] = @Password,
		[CustomerType] = @CustomerType,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[TotalAmount] = @TotalAmount,
		[PaidAmount] = @PaidAmount,
		[CreditLine] = @CreditLine,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_CustomersInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomersInsert];
GO

CREATE PROCEDURE [proc_CustomersInsert]
(
	@ID int = NULL output,
	@CustomerName nvarchar(50) = NULL,
	@Company nvarchar(50) = NULL,
	@Address nvarchar(100) = NULL,
	@Phone nvarchar(20) = NULL,
	@Fax nvarchar(20) = NULL,
	@Mobile nvarchar(20) = NULL,
	@Email nvarchar(50) = NULL,
	@Password nvarchar(50) = NULL,
	@CustomerType int = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@TotalAmount numeric(18,2) = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@CreditLine numeric(18,2) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Customers]
	(
		[CustomerName],
		[Company],
		[Address],
		[Phone],
		[Fax],
		[Mobile],
		[Email],
		[Password],
		[CustomerType],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[TotalAmount],
		[PaidAmount],
		[CreditLine],
		[BranchID]
	)
	VALUES
	(
		@CustomerName,
		@Company,
		@Address,
		@Phone,
		@Fax,
		@Mobile,
		@Email,
		@Password,
		@CustomerType,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@TotalAmount,
		@PaidAmount,
		@CreditLine,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomersDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomersDelete];
GO

CREATE PROCEDURE [proc_CustomersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Customers]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerTypeLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerTypeLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerTypeLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_CustomerTypeLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[TypeName],
		[DealerPrice],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID],
		[Price]
	FROM [CustomerType]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerTypeLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerTypeLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerTypeLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerTypeLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerTypeLoadAll];
GO

CREATE PROCEDURE [proc_CustomerTypeLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[TypeName],
		[DealerPrice],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID],
		[Price]
	FROM [CustomerType]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerTypeLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerTypeLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerTypeUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerTypeUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerTypeUpdate];
GO

CREATE PROCEDURE [proc_CustomerTypeUpdate]
(
	@ID int,
	@TypeName nvarchar(50) = NULL,
	@DealerPrice bit = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int,
	@Price int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [CustomerType]
	SET
		[TypeName] = @TypeName,
		[DealerPrice] = @DealerPrice,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[BranchID] = @BranchID,
		[Price] = @Price
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerTypeUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerTypeUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_CustomerTypeInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerTypeInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerTypeInsert];
GO

CREATE PROCEDURE [proc_CustomerTypeInsert]
(
	@ID int = NULL output,
	@TypeName nvarchar(50) = NULL,
	@DealerPrice bit = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int,
	@Price int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [CustomerType]
	(
		[TypeName],
		[DealerPrice],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID],
		[Price]
	)
	VALUES
	(
		@TypeName,
		@DealerPrice,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@BranchID,
		@Price
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerTypeInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerTypeInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_CustomerTypeDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_CustomerTypeDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_CustomerTypeDelete];
GO

CREATE PROCEDURE [proc_CustomerTypeDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [CustomerType]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_CustomerTypeDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_CustomerTypeDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ExpensesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ExpensesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ExpensesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ExpensesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Title],
		[Amount],
		[Description],
		[Purchaser],
		[SpentDate],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[InvoiceNo],
		[BranchID],
		[PaymentMethodID]
	FROM [Expenses]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ExpensesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ExpensesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ExpensesLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ExpensesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ExpensesLoadAll];
GO

CREATE PROCEDURE [proc_ExpensesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Title],
		[Amount],
		[Description],
		[Purchaser],
		[SpentDate],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[InvoiceNo],
		[BranchID],
		[PaymentMethodID]
	FROM [Expenses]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ExpensesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ExpensesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ExpensesUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ExpensesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ExpensesUpdate];
GO

CREATE PROCEDURE [proc_ExpensesUpdate]
(
	@ID int,
	@Title nvarchar(200) = NULL,
	@Amount decimal(18,2) = NULL,
	@Description nvarchar(1000) = NULL,
	@Purchaser nvarchar(50) = NULL,
	@SpentDate datetime = NULL,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@InvoiceNo nvarchar(20) = NULL,
	@BranchID int = NULL,
	@PaymentMethodID int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Expenses]
	SET
		[Title] = @Title,
		[Amount] = @Amount,
		[Description] = @Description,
		[Purchaser] = @Purchaser,
		[SpentDate] = @SpentDate,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Deleted] = @Deleted,
		[InvoiceNo] = @InvoiceNo,
		[BranchID] = @BranchID,
		[PaymentMethodID] = @PaymentMethodID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ExpensesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ExpensesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ExpensesInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ExpensesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ExpensesInsert];
GO

CREATE PROCEDURE [proc_ExpensesInsert]
(
	@ID int = NULL output,
	@Title nvarchar(200) = NULL,
	@Amount decimal(18,2) = NULL,
	@Description nvarchar(1000) = NULL,
	@Purchaser nvarchar(50) = NULL,
	@SpentDate datetime = NULL,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@InvoiceNo nvarchar(20) = NULL,
	@BranchID int = NULL,
	@PaymentMethodID int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Expenses]
	(
		[Title],
		[Amount],
		[Description],
		[Purchaser],
		[SpentDate],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[InvoiceNo],
		[BranchID],
		[PaymentMethodID]
	)
	VALUES
	(
		@Title,
		@Amount,
		@Description,
		@Purchaser,
		@SpentDate,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Deleted,
		@InvoiceNo,
		@BranchID,
		@PaymentMethodID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ExpensesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ExpensesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ExpensesDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ExpensesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ExpensesDelete];
GO

CREATE PROCEDURE [proc_ExpensesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Expenses]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ExpensesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ExpensesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_HomeBannersLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_HomeBannersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_HomeBannersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_HomeBannersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FileName],
		[Description],
		[Deleted],
		[LastModifiedDate],
		[URL]
	FROM [HomeBanners]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_HomeBannersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_HomeBannersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_HomeBannersLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_HomeBannersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_HomeBannersLoadAll];
GO

CREATE PROCEDURE [proc_HomeBannersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FileName],
		[Description],
		[Deleted],
		[LastModifiedDate],
		[URL]
	FROM [HomeBanners]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_HomeBannersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_HomeBannersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_HomeBannersUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_HomeBannersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_HomeBannersUpdate];
GO

CREATE PROCEDURE [proc_HomeBannersUpdate]
(
	@ID int,
	@FileName nvarchar(500) = NULL,
	@Description nvarchar(500) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@URL nvarchar(500) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [HomeBanners]
	SET
		[FileName] = @FileName,
		[Description] = @Description,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[URL] = @URL
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_HomeBannersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_HomeBannersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_HomeBannersInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_HomeBannersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_HomeBannersInsert];
GO

CREATE PROCEDURE [proc_HomeBannersInsert]
(
	@ID int = NULL output,
	@FileName nvarchar(500) = NULL,
	@Description nvarchar(500) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@URL nvarchar(500) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [HomeBanners]
	(
		[FileName],
		[Description],
		[Deleted],
		[LastModifiedDate],
		[URL]
	)
	VALUES
	(
		@FileName,
		@Description,
		@Deleted,
		@LastModifiedDate,
		@URL
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_HomeBannersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_HomeBannersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_HomeBannersDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_HomeBannersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_HomeBannersDelete];
GO

CREATE PROCEDURE [proc_HomeBannersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [HomeBanners]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_HomeBannersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_HomeBannersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoiceDetailsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceDetailsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceDetailsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_InvoiceDetailsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[InvoiceID],
		[ProductID],
		[IMEI],
		[Description],
		[Quantity],
		[GST],
		[UnitPrice],
		[Cost],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Discount],
		[ItemType],
		[BranchID]
	FROM [InvoiceDetails]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceDetailsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceDetailsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoiceDetailsLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceDetailsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceDetailsLoadAll];
GO

CREATE PROCEDURE [proc_InvoiceDetailsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[InvoiceID],
		[ProductID],
		[IMEI],
		[Description],
		[Quantity],
		[GST],
		[UnitPrice],
		[Cost],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Discount],
		[ItemType],
		[BranchID]
	FROM [InvoiceDetails]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceDetailsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceDetailsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoiceDetailsUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceDetailsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceDetailsUpdate];
GO

CREATE PROCEDURE [proc_InvoiceDetailsUpdate]
(
	@ID int,
	@InvoiceID int = NULL,
	@ProductID int = NULL,
	@IMEI nvarchar(20) = NULL,
	@Description nvarchar(1000) = NULL,
	@Quantity int = NULL,
	@GST numeric(18,2) = NULL,
	@UnitPrice numeric(18,2) = NULL,
	@Cost numeric(18,2) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Discount numeric(18,2) = NULL,
	@ItemType tinyint = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [InvoiceDetails]
	SET
		[InvoiceID] = @InvoiceID,
		[ProductID] = @ProductID,
		[IMEI] = @IMEI,
		[Description] = @Description,
		[Quantity] = @Quantity,
		[GST] = @GST,
		[UnitPrice] = @UnitPrice,
		[Cost] = @Cost,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Discount] = @Discount,
		[ItemType] = @ItemType,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceDetailsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceDetailsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_InvoiceDetailsInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceDetailsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceDetailsInsert];
GO

CREATE PROCEDURE [proc_InvoiceDetailsInsert]
(
	@ID int = NULL output,
	@InvoiceID int = NULL,
	@ProductID int = NULL,
	@IMEI nvarchar(20) = NULL,
	@Description nvarchar(1000) = NULL,
	@Quantity int = NULL,
	@GST numeric(18,2) = NULL,
	@UnitPrice numeric(18,2) = NULL,
	@Cost numeric(18,2) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Discount numeric(18,2) = NULL,
	@ItemType tinyint = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [InvoiceDetails]
	(
		[InvoiceID],
		[ProductID],
		[IMEI],
		[Description],
		[Quantity],
		[GST],
		[UnitPrice],
		[Cost],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Discount],
		[ItemType],
		[BranchID]
	)
	VALUES
	(
		@InvoiceID,
		@ProductID,
		@IMEI,
		@Description,
		@Quantity,
		@GST,
		@UnitPrice,
		@Cost,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Discount,
		@ItemType,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceDetailsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceDetailsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoiceDetailsDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceDetailsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceDetailsDelete];
GO

CREATE PROCEDURE [proc_InvoiceDetailsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [InvoiceDetails]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceDetailsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceDetailsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoicePaymentHistoriesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicePaymentHistoriesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicePaymentHistoriesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_InvoicePaymentHistoriesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[InvoiceID],
		[PaymentMethodID],
		[PaidAmount],
		[PaidDate],
		[SaleUser],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [InvoicePaymentHistories]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoicePaymentHistoriesLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicePaymentHistoriesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicePaymentHistoriesLoadAll];
GO

CREATE PROCEDURE [proc_InvoicePaymentHistoriesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[InvoiceID],
		[PaymentMethodID],
		[PaidAmount],
		[PaidDate],
		[SaleUser],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [InvoicePaymentHistories]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoicePaymentHistoriesUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicePaymentHistoriesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicePaymentHistoriesUpdate];
GO

CREATE PROCEDURE [proc_InvoicePaymentHistoriesUpdate]
(
	@ID int,
	@InvoiceID int = NULL,
	@PaymentMethodID int = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@PaidDate datetime = NULL,
	@SaleUser int = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [InvoicePaymentHistories]
	SET
		[InvoiceID] = @InvoiceID,
		[PaymentMethodID] = @PaymentMethodID,
		[PaidAmount] = @PaidAmount,
		[PaidDate] = @PaidDate,
		[SaleUser] = @SaleUser,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_InvoicePaymentHistoriesInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicePaymentHistoriesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicePaymentHistoriesInsert];
GO

CREATE PROCEDURE [proc_InvoicePaymentHistoriesInsert]
(
	@ID int = NULL output,
	@InvoiceID int = NULL,
	@PaymentMethodID int = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@PaidDate datetime = NULL,
	@SaleUser int = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [InvoicePaymentHistories]
	(
		[InvoiceID],
		[PaymentMethodID],
		[PaidAmount],
		[PaidDate],
		[SaleUser],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	)
	VALUES
	(
		@InvoiceID,
		@PaymentMethodID,
		@PaidAmount,
		@PaidDate,
		@SaleUser,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoicePaymentHistoriesDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicePaymentHistoriesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicePaymentHistoriesDelete];
GO

CREATE PROCEDURE [proc_InvoicePaymentHistoriesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [InvoicePaymentHistories]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicePaymentHistoriesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoicesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_InvoicesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[InvoiceNo],
		[InvoiceTypeID],
		[SaleUser],
		[CustomerID],
		[CustomerName],
		[GSTTotalAmount],
		[TotalAmount],
		[PaidAmount],
		[Note],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[CreatedDate],
		[CreatedByUser],
		[IsRetail],
		[InvoiceCategory],
		[BranchID],
		[VoucherID],
		[SpecialDiscount]
	FROM [Invoices]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoicesLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicesLoadAll];
GO

CREATE PROCEDURE [proc_InvoicesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[InvoiceNo],
		[InvoiceTypeID],
		[SaleUser],
		[CustomerID],
		[CustomerName],
		[GSTTotalAmount],
		[TotalAmount],
		[PaidAmount],
		[Note],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[CreatedDate],
		[CreatedByUser],
		[IsRetail],
		[InvoiceCategory],
		[BranchID],
		[VoucherID],
		[SpecialDiscount]
	FROM [Invoices]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoicesUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicesUpdate];
GO

CREATE PROCEDURE [proc_InvoicesUpdate]
(
	@ID int,
	@InvoiceNo char(10) = NULL,
	@InvoiceTypeID int = NULL,
	@SaleUser int = NULL,
	@CustomerID int = NULL,
	@CustomerName nvarchar(50) = NULL,
	@GSTTotalAmount numeric(18,2) = NULL,
	@TotalAmount numeric(18,2) = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@Note nvarchar(500) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@CreatedDate datetime = NULL,
	@CreatedByUser int = NULL,
	@IsRetail bit = NULL,
	@InvoiceCategory tinyint = NULL,
	@BranchID int,
	@VoucherID uniqueidentifier = NULL,
	@SpecialDiscount decimal(18,2) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Invoices]
	SET
		[InvoiceNo] = @InvoiceNo,
		[InvoiceTypeID] = @InvoiceTypeID,
		[SaleUser] = @SaleUser,
		[CustomerID] = @CustomerID,
		[CustomerName] = @CustomerName,
		[GSTTotalAmount] = @GSTTotalAmount,
		[TotalAmount] = @TotalAmount,
		[PaidAmount] = @PaidAmount,
		[Note] = @Note,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[CreatedDate] = @CreatedDate,
		[CreatedByUser] = @CreatedByUser,
		[IsRetail] = @IsRetail,
		[InvoiceCategory] = @InvoiceCategory,
		[BranchID] = @BranchID,
		[VoucherID] = @VoucherID,
		[SpecialDiscount] = @SpecialDiscount
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_InvoicesInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicesInsert];
GO

CREATE PROCEDURE [proc_InvoicesInsert]
(
	@ID int = NULL output,
	@InvoiceNo char(10) = NULL,
	@InvoiceTypeID int = NULL,
	@SaleUser int = NULL,
	@CustomerID int = NULL,
	@CustomerName nvarchar(50) = NULL,
	@GSTTotalAmount numeric(18,2) = NULL,
	@TotalAmount numeric(18,2) = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@Note nvarchar(500) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@CreatedDate datetime = NULL,
	@CreatedByUser int = NULL,
	@IsRetail bit = NULL,
	@InvoiceCategory tinyint = NULL,
	@BranchID int,
	@VoucherID uniqueidentifier = NULL,
	@SpecialDiscount decimal(18,2) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Invoices]
	(
		[InvoiceNo],
		[InvoiceTypeID],
		[SaleUser],
		[CustomerID],
		[CustomerName],
		[GSTTotalAmount],
		[TotalAmount],
		[PaidAmount],
		[Note],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[CreatedDate],
		[CreatedByUser],
		[IsRetail],
		[InvoiceCategory],
		[BranchID],
		[VoucherID],
		[SpecialDiscount]
	)
	VALUES
	(
		@InvoiceNo,
		@InvoiceTypeID,
		@SaleUser,
		@CustomerID,
		@CustomerName,
		@GSTTotalAmount,
		@TotalAmount,
		@PaidAmount,
		@Note,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@CreatedDate,
		@CreatedByUser,
		@IsRetail,
		@InvoiceCategory,
		@BranchID,
		@VoucherID,
		@SpecialDiscount
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoicesDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoicesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoicesDelete];
GO

CREATE PROCEDURE [proc_InvoicesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Invoices]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoicesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoicesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoiceTypeLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceTypeLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceTypeLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_InvoiceTypeLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[InvoiceTypeName],
		[Default]
	FROM [InvoiceType]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceTypeLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceTypeLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoiceTypeLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceTypeLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceTypeLoadAll];
GO

CREATE PROCEDURE [proc_InvoiceTypeLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[InvoiceTypeName],
		[Default]
	FROM [InvoiceType]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceTypeLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceTypeLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoiceTypeUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceTypeUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceTypeUpdate];
GO

CREATE PROCEDURE [proc_InvoiceTypeUpdate]
(
	@ID int,
	@InvoiceTypeName nvarchar(50) = NULL,
	@Default bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [InvoiceType]
	SET
		[InvoiceTypeName] = @InvoiceTypeName,
		[Default] = @Default
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceTypeUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceTypeUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_InvoiceTypeInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceTypeInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceTypeInsert];
GO

CREATE PROCEDURE [proc_InvoiceTypeInsert]
(
	@ID int,
	@InvoiceTypeName nvarchar(50) = NULL,
	@Default bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [InvoiceType]
	(
		[ID],
		[InvoiceTypeName],
		[Default]
	)
	VALUES
	(
		@ID,
		@InvoiceTypeName,
		@Default
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceTypeInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceTypeInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_InvoiceTypeDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_InvoiceTypeDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_InvoiceTypeDelete];
GO

CREATE PROCEDURE [proc_InvoiceTypeDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [InvoiceType]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_InvoiceTypeDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_InvoiceTypeDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_LoanPhonesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_LoanPhonesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_LoanPhonesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_LoanPhonesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[BrandID],
		[ProductName],
		[IMEI],
		[LastModifiedDate],
		[Free],
		[Deleted],
		[BranchID]
	FROM [LoanPhones]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_LoanPhonesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_LoanPhonesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_LoanPhonesLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_LoanPhonesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_LoanPhonesLoadAll];
GO

CREATE PROCEDURE [proc_LoanPhonesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[BrandID],
		[ProductName],
		[IMEI],
		[LastModifiedDate],
		[Free],
		[Deleted],
		[BranchID]
	FROM [LoanPhones]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_LoanPhonesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_LoanPhonesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_LoanPhonesUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_LoanPhonesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_LoanPhonesUpdate];
GO

CREATE PROCEDURE [proc_LoanPhonesUpdate]
(
	@ID int,
	@BrandID int = NULL,
	@ProductName nvarchar(50) = NULL,
	@IMEI nvarchar(20) = NULL,
	@LastModifiedDate datetime = NULL,
	@Free bit = NULL,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [LoanPhones]
	SET
		[BrandID] = @BrandID,
		[ProductName] = @ProductName,
		[IMEI] = @IMEI,
		[LastModifiedDate] = @LastModifiedDate,
		[Free] = @Free,
		[Deleted] = @Deleted,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_LoanPhonesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_LoanPhonesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_LoanPhonesInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_LoanPhonesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_LoanPhonesInsert];
GO

CREATE PROCEDURE [proc_LoanPhonesInsert]
(
	@ID int = NULL output,
	@BrandID int = NULL,
	@ProductName nvarchar(50) = NULL,
	@IMEI nvarchar(20) = NULL,
	@LastModifiedDate datetime = NULL,
	@Free bit = NULL,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [LoanPhones]
	(
		[BrandID],
		[ProductName],
		[IMEI],
		[LastModifiedDate],
		[Free],
		[Deleted],
		[BranchID]
	)
	VALUES
	(
		@BrandID,
		@ProductName,
		@IMEI,
		@LastModifiedDate,
		@Free,
		@Deleted,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_LoanPhonesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_LoanPhonesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_LoanPhonesDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_LoanPhonesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_LoanPhonesDelete];
GO

CREATE PROCEDURE [proc_LoanPhonesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [LoanPhones]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_LoanPhonesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_LoanPhonesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_NetworksLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_NetworksLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_NetworksLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_NetworksLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[NetworkName],
		[DealerCode],
		[PostalAddress],
		[DealerManagerName],
		[DealerManagerPhone],
		[DealerManagerEmail],
		[CommissionEnquiryName],
		[CommissionEnquiryPhone],
		[CommissionEnquiryEmail],
		[OtherName],
		[OtherPhone],
		[OtherEmail],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[BranchID]
	FROM [Networks]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_NetworksLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_NetworksLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_NetworksLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_NetworksLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_NetworksLoadAll];
GO

CREATE PROCEDURE [proc_NetworksLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[NetworkName],
		[DealerCode],
		[PostalAddress],
		[DealerManagerName],
		[DealerManagerPhone],
		[DealerManagerEmail],
		[CommissionEnquiryName],
		[CommissionEnquiryPhone],
		[CommissionEnquiryEmail],
		[OtherName],
		[OtherPhone],
		[OtherEmail],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[BranchID]
	FROM [Networks]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_NetworksLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_NetworksLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_NetworksUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_NetworksUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_NetworksUpdate];
GO

CREATE PROCEDURE [proc_NetworksUpdate]
(
	@ID int,
	@NetworkName nvarchar(50) = NULL,
	@DealerCode nvarchar(50) = NULL,
	@PostalAddress nvarchar(100) = NULL,
	@DealerManagerName nvarchar(50) = NULL,
	@DealerManagerPhone nvarchar(20) = NULL,
	@DealerManagerEmail nvarchar(50) = NULL,
	@CommissionEnquiryName nvarchar(50) = NULL,
	@CommissionEnquiryPhone nvarchar(20) = NULL,
	@CommissionEnquiryEmail nvarchar(50) = NULL,
	@OtherName nvarchar(50) = NULL,
	@OtherPhone nvarchar(20) = NULL,
	@OtherEmail nvarchar(50) = NULL,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Networks]
	SET
		[NetworkName] = @NetworkName,
		[DealerCode] = @DealerCode,
		[PostalAddress] = @PostalAddress,
		[DealerManagerName] = @DealerManagerName,
		[DealerManagerPhone] = @DealerManagerPhone,
		[DealerManagerEmail] = @DealerManagerEmail,
		[CommissionEnquiryName] = @CommissionEnquiryName,
		[CommissionEnquiryPhone] = @CommissionEnquiryPhone,
		[CommissionEnquiryEmail] = @CommissionEnquiryEmail,
		[OtherName] = @OtherName,
		[OtherPhone] = @OtherPhone,
		[OtherEmail] = @OtherEmail,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Deleted] = @Deleted,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_NetworksUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_NetworksUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_NetworksInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_NetworksInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_NetworksInsert];
GO

CREATE PROCEDURE [proc_NetworksInsert]
(
	@ID int = NULL output,
	@NetworkName nvarchar(50) = NULL,
	@DealerCode nvarchar(50) = NULL,
	@PostalAddress nvarchar(100) = NULL,
	@DealerManagerName nvarchar(50) = NULL,
	@DealerManagerPhone nvarchar(20) = NULL,
	@DealerManagerEmail nvarchar(50) = NULL,
	@CommissionEnquiryName nvarchar(50) = NULL,
	@CommissionEnquiryPhone nvarchar(20) = NULL,
	@CommissionEnquiryEmail nvarchar(50) = NULL,
	@OtherName nvarchar(50) = NULL,
	@OtherPhone nvarchar(20) = NULL,
	@OtherEmail nvarchar(50) = NULL,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Networks]
	(
		[NetworkName],
		[DealerCode],
		[PostalAddress],
		[DealerManagerName],
		[DealerManagerPhone],
		[DealerManagerEmail],
		[CommissionEnquiryName],
		[CommissionEnquiryPhone],
		[CommissionEnquiryEmail],
		[OtherName],
		[OtherPhone],
		[OtherEmail],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[BranchID]
	)
	VALUES
	(
		@NetworkName,
		@DealerCode,
		@PostalAddress,
		@DealerManagerName,
		@DealerManagerPhone,
		@DealerManagerEmail,
		@CommissionEnquiryName,
		@CommissionEnquiryPhone,
		@CommissionEnquiryEmail,
		@OtherName,
		@OtherPhone,
		@OtherEmail,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Deleted,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_NetworksInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_NetworksInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_NetworksDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_NetworksDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_NetworksDelete];
GO

CREATE PROCEDURE [proc_NetworksDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Networks]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_NetworksDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_NetworksDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_OrderItemsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderItemsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderItemsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_OrderItemsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[OrderID],
		[ProductID],
		[Quantity],
		[UnitCost],
		[UnitPrice],
		[UnitDealerPrice],
		[CustomerPrice],
		[TotalAmount],
		[GST],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[LastModifiedByCustomer],
		[ProductImage],
		[Name],
		[Category]
	FROM [OrderItems]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderItemsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderItemsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_OrderItemsLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderItemsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderItemsLoadAll];
GO

CREATE PROCEDURE [proc_OrderItemsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[OrderID],
		[ProductID],
		[Quantity],
		[UnitCost],
		[UnitPrice],
		[UnitDealerPrice],
		[CustomerPrice],
		[TotalAmount],
		[GST],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[LastModifiedByCustomer],
		[ProductImage],
		[Name],
		[Category]
	FROM [OrderItems]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderItemsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderItemsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_OrderItemsUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderItemsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderItemsUpdate];
GO

CREATE PROCEDURE [proc_OrderItemsUpdate]
(
	@ID int,
	@OrderID int,
	@ProductID int,
	@Quantity int,
	@UnitCost numeric(18,2),
	@UnitPrice numeric(18,2),
	@UnitDealerPrice numeric(18,2),
	@CustomerPrice numeric(18,2),
	@TotalAmount numeric(18,2),
	@GST numeric(18,2) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@LastModifiedByCustomer int = NULL,
	@ProductImage int = NULL,
	@Name nchar(10) = NULL,
	@Category int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [OrderItems]
	SET
		[OrderID] = @OrderID,
		[ProductID] = @ProductID,
		[Quantity] = @Quantity,
		[UnitCost] = @UnitCost,
		[UnitPrice] = @UnitPrice,
		[UnitDealerPrice] = @UnitDealerPrice,
		[CustomerPrice] = @CustomerPrice,
		[TotalAmount] = @TotalAmount,
		[GST] = @GST,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[LastModifiedByCustomer] = @LastModifiedByCustomer,
		[ProductImage] = @ProductImage,
		[Name] = @Name,
		[Category] = @Category
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderItemsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderItemsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_OrderItemsInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderItemsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderItemsInsert];
GO

CREATE PROCEDURE [proc_OrderItemsInsert]
(
	@ID int = NULL output,
	@OrderID int,
	@ProductID int,
	@Quantity int,
	@UnitCost numeric(18,2),
	@UnitPrice numeric(18,2),
	@UnitDealerPrice numeric(18,2),
	@CustomerPrice numeric(18,2),
	@TotalAmount numeric(18,2),
	@GST numeric(18,2) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@LastModifiedByCustomer int = NULL,
	@ProductImage int = NULL,
	@Name nchar(10) = NULL,
	@Category int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [OrderItems]
	(
		[OrderID],
		[ProductID],
		[Quantity],
		[UnitCost],
		[UnitPrice],
		[UnitDealerPrice],
		[CustomerPrice],
		[TotalAmount],
		[GST],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[LastModifiedByCustomer],
		[ProductImage],
		[Name],
		[Category]
	)
	VALUES
	(
		@OrderID,
		@ProductID,
		@Quantity,
		@UnitCost,
		@UnitPrice,
		@UnitDealerPrice,
		@CustomerPrice,
		@TotalAmount,
		@GST,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@LastModifiedByCustomer,
		@ProductImage,
		@Name,
		@Category
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderItemsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderItemsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_OrderItemsDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderItemsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderItemsDelete];
GO

CREATE PROCEDURE [proc_OrderItemsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [OrderItems]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderItemsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderItemsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_OrderStatusLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderStatusLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderStatusLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_OrderStatusLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[StatusName]
	FROM [OrderStatus]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderStatusLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderStatusLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_OrderStatusLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderStatusLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderStatusLoadAll];
GO

CREATE PROCEDURE [proc_OrderStatusLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[StatusName]
	FROM [OrderStatus]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderStatusLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderStatusLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_OrderStatusUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderStatusUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderStatusUpdate];
GO

CREATE PROCEDURE [proc_OrderStatusUpdate]
(
	@ID int,
	@StatusName nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [OrderStatus]
	SET
		[StatusName] = @StatusName
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderStatusUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderStatusUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_OrderStatusInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderStatusInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderStatusInsert];
GO

CREATE PROCEDURE [proc_OrderStatusInsert]
(
	@ID int,
	@StatusName nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [OrderStatus]
	(
		[ID],
		[StatusName]
	)
	VALUES
	(
		@ID,
		@StatusName
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderStatusInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderStatusInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_OrderStatusDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_OrderStatusDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_OrderStatusDelete];
GO

CREATE PROCEDURE [proc_OrderStatusDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [OrderStatus]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_OrderStatusDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_OrderStatusDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PageBannersLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageBannersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageBannersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_PageBannersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FileName],
		[Title],
		[Description],
		[Active],
		[URL],
		[Page]
	FROM [PageBanners]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageBannersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageBannersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PageBannersLoadAll]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageBannersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageBannersLoadAll];
GO

CREATE PROCEDURE [proc_PageBannersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FileName],
		[Title],
		[Description],
		[Active],
		[URL],
		[Page]
	FROM [PageBanners]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageBannersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageBannersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PageBannersUpdate]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageBannersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageBannersUpdate];
GO

CREATE PROCEDURE [proc_PageBannersUpdate]
(
	@ID int,
	@FileName nvarchar(500),
	@Title nvarchar(100) = NULL,
	@Description nvarchar(500) = NULL,
	@Active bit,
	@URL nvarchar(500) = NULL,
	@Page nvarchar(100) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [PageBanners]
	SET
		[FileName] = @FileName,
		[Title] = @Title,
		[Description] = @Description,
		[Active] = @Active,
		[URL] = @URL,
		[Page] = @Page
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageBannersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageBannersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_PageBannersInsert]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageBannersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageBannersInsert];
GO

CREATE PROCEDURE [proc_PageBannersInsert]
(
	@ID int = NULL output,
	@FileName nvarchar(500),
	@Title nvarchar(100) = NULL,
	@Description nvarchar(500) = NULL,
	@Active bit,
	@URL nvarchar(500) = NULL,
	@Page nvarchar(100) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [PageBanners]
	(
		[FileName],
		[Title],
		[Description],
		[Active],
		[URL],
		[Page]
	)
	VALUES
	(
		@FileName,
		@Title,
		@Description,
		@Active,
		@URL,
		@Page
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageBannersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageBannersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PageBannersDelete]    Script Date: 9/17/2011 5:25:58 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageBannersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageBannersDelete];
GO

CREATE PROCEDURE [proc_PageBannersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [PageBanners]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageBannersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageBannersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PageFilesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageFilesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageFilesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_PageFilesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[PageFileName],
		[Description],
		[Deleted]
	FROM [PageFiles]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageFilesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageFilesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PageFilesLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageFilesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageFilesLoadAll];
GO

CREATE PROCEDURE [proc_PageFilesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[PageFileName],
		[Description],
		[Deleted]
	FROM [PageFiles]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageFilesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageFilesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PageFilesUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageFilesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageFilesUpdate];
GO

CREATE PROCEDURE [proc_PageFilesUpdate]
(
	@ID int,
	@PageFileName nvarchar(200),
	@Description nvarchar(200) = NULL,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [PageFiles]
	SET
		[PageFileName] = @PageFileName,
		[Description] = @Description,
		[Deleted] = @Deleted
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageFilesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageFilesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_PageFilesInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageFilesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageFilesInsert];
GO

CREATE PROCEDURE [proc_PageFilesInsert]
(
	@ID int,
	@PageFileName nvarchar(200),
	@Description nvarchar(200) = NULL,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [PageFiles]
	(
		[ID],
		[PageFileName],
		[Description],
		[Deleted]
	)
	VALUES
	(
		@ID,
		@PageFileName,
		@Description,
		@Deleted
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageFilesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageFilesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PageFilesDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PageFilesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PageFilesDelete];
GO

CREATE PROCEDURE [proc_PageFilesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [PageFiles]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PageFilesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_PageFilesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PaperPricesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaperPricesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaperPricesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_PaperPricesLoadByPrimaryKey]
(
	@PaperID int,
	@Quantity int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[PaperID],
		[Quantity],
		[UnitPrice]
	FROM [PaperPrices]
	WHERE
		([PaperID] = @PaperID) AND
		([Quantity] = @Quantity)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaperPricesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaperPricesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PaperPricesLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaperPricesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaperPricesLoadAll];
GO

CREATE PROCEDURE [proc_PaperPricesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[PaperID],
		[Quantity],
		[UnitPrice]
	FROM [PaperPrices]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaperPricesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaperPricesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PaperPricesUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaperPricesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaperPricesUpdate];
GO

CREATE PROCEDURE [proc_PaperPricesUpdate]
(
	@PaperID int,
	@Quantity int,
	@UnitPrice decimal(18,2)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [PaperPrices]
	SET
		[UnitPrice] = @UnitPrice
	WHERE
		[PaperID] = @PaperID
	AND	[Quantity] = @Quantity


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaperPricesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaperPricesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_PaperPricesInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaperPricesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaperPricesInsert];
GO

CREATE PROCEDURE [proc_PaperPricesInsert]
(
	@PaperID int,
	@Quantity int,
	@UnitPrice decimal(18,2)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [PaperPrices]
	(
		[PaperID],
		[Quantity],
		[UnitPrice]
	)
	VALUES
	(
		@PaperID,
		@Quantity,
		@UnitPrice
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaperPricesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaperPricesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PaperPricesDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaperPricesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaperPricesDelete];
GO

CREATE PROCEDURE [proc_PaperPricesDelete]
(
	@PaperID int,
	@Quantity int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [PaperPrices]
	WHERE
		[PaperID] = @PaperID AND
		[Quantity] = @Quantity
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaperPricesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaperPricesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PaymentMethodLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaymentMethodLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaymentMethodLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_PaymentMethodLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Name],
		[Description],
		[MethodType],
		[Default]
	FROM [PaymentMethod]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaymentMethodLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaymentMethodLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PaymentMethodLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaymentMethodLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaymentMethodLoadAll];
GO

CREATE PROCEDURE [proc_PaymentMethodLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Name],
		[Description],
		[MethodType],
		[Default]
	FROM [PaymentMethod]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaymentMethodLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaymentMethodLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PaymentMethodUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaymentMethodUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaymentMethodUpdate];
GO

CREATE PROCEDURE [proc_PaymentMethodUpdate]
(
	@ID int,
	@Name nvarchar(50) = NULL,
	@Description nvarchar(50) = NULL,
	@MethodType char(1) = NULL,
	@Default bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [PaymentMethod]
	SET
		[Name] = @Name,
		[Description] = @Description,
		[MethodType] = @MethodType,
		[Default] = @Default
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaymentMethodUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaymentMethodUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_PaymentMethodInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaymentMethodInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaymentMethodInsert];
GO

CREATE PROCEDURE [proc_PaymentMethodInsert]
(
	@ID int,
	@Name nvarchar(50) = NULL,
	@Description nvarchar(50) = NULL,
	@MethodType char(1) = NULL,
	@Default bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [PaymentMethod]
	(
		[ID],
		[Name],
		[Description],
		[MethodType],
		[Default]
	)
	VALUES
	(
		@ID,
		@Name,
		@Description,
		@MethodType,
		@Default
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaymentMethodInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaymentMethodInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PaymentMethodDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PaymentMethodDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PaymentMethodDelete];
GO

CREATE PROCEDURE [proc_PaymentMethodDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [PaymentMethod]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PaymentMethodDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_PaymentMethodDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProblemCategoriesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemCategoriesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemCategoriesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ProblemCategoriesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProblemCategoryName],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [ProblemCategories]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemCategoriesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemCategoriesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProblemCategoriesLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemCategoriesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemCategoriesLoadAll];
GO

CREATE PROCEDURE [proc_ProblemCategoriesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProblemCategoryName],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [ProblemCategories]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemCategoriesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemCategoriesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProblemCategoriesUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemCategoriesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemCategoriesUpdate];
GO

CREATE PROCEDURE [proc_ProblemCategoriesUpdate]
(
	@ID int,
	@ProblemCategoryName nvarchar(50),
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [ProblemCategories]
	SET
		[ProblemCategoryName] = @ProblemCategoryName,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemCategoriesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemCategoriesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ProblemCategoriesInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemCategoriesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemCategoriesInsert];
GO

CREATE PROCEDURE [proc_ProblemCategoriesInsert]
(
	@ID int = NULL output,
	@ProblemCategoryName nvarchar(50),
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [ProblemCategories]
	(
		[ProblemCategoryName],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	)
	VALUES
	(
		@ProblemCategoryName,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemCategoriesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemCategoriesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProblemCategoriesDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemCategoriesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemCategoriesDelete];
GO

CREATE PROCEDURE [proc_ProblemCategoriesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [ProblemCategories]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemCategoriesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemCategoriesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProblemsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ProblemsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Description],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[CategoryID],
		[BranchID]
	FROM [Problems]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProblemsLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemsLoadAll];
GO

CREATE PROCEDURE [proc_ProblemsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Description],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[CategoryID],
		[BranchID]
	FROM [Problems]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProblemsUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemsUpdate];
GO

CREATE PROCEDURE [proc_ProblemsUpdate]
(
	@ID int,
	@Description nvarchar(100),
	@LastModifiedDate datetime,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@CategoryID int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Problems]
	SET
		[Description] = @Description,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Deleted] = @Deleted,
		[CategoryID] = @CategoryID,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ProblemsInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemsInsert];
GO

CREATE PROCEDURE [proc_ProblemsInsert]
(
	@ID int = NULL output,
	@Description nvarchar(100),
	@LastModifiedDate datetime,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@CategoryID int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Problems]
	(
		[Description],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[CategoryID],
		[BranchID]
	)
	VALUES
	(
		@Description,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Deleted,
		@CategoryID,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProblemsDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProblemsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProblemsDelete];
GO

CREATE PROCEDURE [proc_ProblemsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Problems]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProblemsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProblemsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductDetailHistoriesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailHistoriesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailHistoriesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ProductDetailHistoriesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductDetailID],
		[ProductStatusID],
		[StockLocationID],
		[SavedDate],
		[UserID],
		[CustomerID],
		[SupplierID],
		[Cost],
		[Description],
		[BranchID]
	FROM [ProductDetailHistories]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailHistoriesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailHistoriesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductDetailHistoriesLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailHistoriesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailHistoriesLoadAll];
GO

CREATE PROCEDURE [proc_ProductDetailHistoriesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductDetailID],
		[ProductStatusID],
		[StockLocationID],
		[SavedDate],
		[UserID],
		[CustomerID],
		[SupplierID],
		[Cost],
		[Description],
		[BranchID]
	FROM [ProductDetailHistories]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailHistoriesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailHistoriesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductDetailHistoriesUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailHistoriesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailHistoriesUpdate];
GO

CREATE PROCEDURE [proc_ProductDetailHistoriesUpdate]
(
	@ID int,
	@ProductDetailID int = NULL,
	@ProductStatusID int = NULL,
	@StockLocationID int = NULL,
	@SavedDate datetime = NULL,
	@UserID int = NULL,
	@CustomerID int = NULL,
	@SupplierID int = NULL,
	@Cost numeric(18,2) = NULL,
	@Description nvarchar(1000) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [ProductDetailHistories]
	SET
		[ProductDetailID] = @ProductDetailID,
		[ProductStatusID] = @ProductStatusID,
		[StockLocationID] = @StockLocationID,
		[SavedDate] = @SavedDate,
		[UserID] = @UserID,
		[CustomerID] = @CustomerID,
		[SupplierID] = @SupplierID,
		[Cost] = @Cost,
		[Description] = @Description,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailHistoriesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailHistoriesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ProductDetailHistoriesInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailHistoriesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailHistoriesInsert];
GO

CREATE PROCEDURE [proc_ProductDetailHistoriesInsert]
(
	@ID int = NULL output,
	@ProductDetailID int = NULL,
	@ProductStatusID int = NULL,
	@StockLocationID int = NULL,
	@SavedDate datetime = NULL,
	@UserID int = NULL,
	@CustomerID int = NULL,
	@SupplierID int = NULL,
	@Cost numeric(18,2) = NULL,
	@Description nvarchar(1000) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [ProductDetailHistories]
	(
		[ProductDetailID],
		[ProductStatusID],
		[StockLocationID],
		[SavedDate],
		[UserID],
		[CustomerID],
		[SupplierID],
		[Cost],
		[Description],
		[BranchID]
	)
	VALUES
	(
		@ProductDetailID,
		@ProductStatusID,
		@StockLocationID,
		@SavedDate,
		@UserID,
		@CustomerID,
		@SupplierID,
		@Cost,
		@Description,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailHistoriesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailHistoriesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductDetailHistoriesDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailHistoriesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailHistoriesDelete];
GO

CREATE PROCEDURE [proc_ProductDetailHistoriesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [ProductDetailHistories]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailHistoriesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailHistoriesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductDetailsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ProductDetailsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductID],
		[Description],
		[IMEI],
		[SupplierID],
		[StoreDate],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[StockLocationID],
		[ProductStatusID],
		[BranchID]
	FROM [ProductDetails]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductDetailsLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailsLoadAll];
GO

CREATE PROCEDURE [proc_ProductDetailsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductID],
		[Description],
		[IMEI],
		[SupplierID],
		[StoreDate],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[StockLocationID],
		[ProductStatusID],
		[BranchID]
	FROM [ProductDetails]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductDetailsUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailsUpdate];
GO

CREATE PROCEDURE [proc_ProductDetailsUpdate]
(
	@ID int,
	@ProductID int = NULL,
	@Description nvarchar(500) = NULL,
	@IMEI nvarchar(20),
	@SupplierID int = NULL,
	@StoreDate datetime = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@StockLocationID int = NULL,
	@ProductStatusID int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [ProductDetails]
	SET
		[ProductID] = @ProductID,
		[Description] = @Description,
		[IMEI] = @IMEI,
		[SupplierID] = @SupplierID,
		[StoreDate] = @StoreDate,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[StockLocationID] = @StockLocationID,
		[ProductStatusID] = @ProductStatusID,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ProductDetailsInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailsInsert];
GO

CREATE PROCEDURE [proc_ProductDetailsInsert]
(
	@ID int = NULL output,
	@ProductID int = NULL,
	@Description nvarchar(500) = NULL,
	@IMEI nvarchar(20),
	@SupplierID int = NULL,
	@StoreDate datetime = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@StockLocationID int = NULL,
	@ProductStatusID int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [ProductDetails]
	(
		[ProductID],
		[Description],
		[IMEI],
		[SupplierID],
		[StoreDate],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[StockLocationID],
		[ProductStatusID],
		[BranchID]
	)
	VALUES
	(
		@ProductID,
		@Description,
		@IMEI,
		@SupplierID,
		@StoreDate,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@StockLocationID,
		@ProductStatusID,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductDetailsDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductDetailsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductDetailsDelete];
GO

CREATE PROCEDURE [proc_ProductDetailsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [ProductDetails]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductDetailsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductDetailsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductImagesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductImagesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductImagesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ProductImagesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductID],
		[Description],
		[ThumbUrl],
		[OriginalUrl],
		[Default]
	FROM [ProductImages]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductImagesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductImagesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductImagesLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductImagesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductImagesLoadAll];
GO

CREATE PROCEDURE [proc_ProductImagesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductID],
		[Description],
		[ThumbUrl],
		[OriginalUrl],
		[Default]
	FROM [ProductImages]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductImagesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductImagesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductImagesUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductImagesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductImagesUpdate];
GO

CREATE PROCEDURE [proc_ProductImagesUpdate]
(
	@ID int,
	@ProductID int,
	@Description nvarchar(100) = NULL,
	@ThumbUrl nvarchar(500) = NULL,
	@OriginalUrl nvarchar(500) = NULL,
	@Default bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [ProductImages]
	SET
		[ProductID] = @ProductID,
		[Description] = @Description,
		[ThumbUrl] = @ThumbUrl,
		[OriginalUrl] = @OriginalUrl,
		[Default] = @Default
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductImagesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductImagesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ProductImagesInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductImagesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductImagesInsert];
GO

CREATE PROCEDURE [proc_ProductImagesInsert]
(
	@ID int = NULL output,
	@ProductID int,
	@Description nvarchar(100) = NULL,
	@ThumbUrl nvarchar(500) = NULL,
	@OriginalUrl nvarchar(500) = NULL,
	@Default bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [ProductImages]
	(
		[ProductID],
		[Description],
		[ThumbUrl],
		[OriginalUrl],
		[Default]
	)
	VALUES
	(
		@ProductID,
		@Description,
		@ThumbUrl,
		@OriginalUrl,
		@Default
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductImagesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductImagesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductImagesDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductImagesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductImagesDelete];
GO

CREATE PROCEDURE [proc_ProductImagesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [ProductImages]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductImagesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductImagesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ProductsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductName],
		[CategoryID],
		[IMEIAvailable],
		[BrandID],
		[Description],
		[Picture],
		[BarCode],
		[Cost],
		[DealerPrice],
		[SalePrice],
		[Quantity],
		[GST],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[IsNewArrival],
		[IsHotProduct],
		[Thumbnail],
		[IsHomeProduct],
		[IsDealerOnly],
		[SoldQuantity],
		[RegularPrice],
		[BranchID],
		[StockKey],
		[PartnerPrice]
	FROM [Products]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductsLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsLoadAll];
GO

CREATE PROCEDURE [proc_ProductsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductName],
		[CategoryID],
		[IMEIAvailable],
		[BrandID],
		[Description],
		[Picture],
		[BarCode],
		[Cost],
		[DealerPrice],
		[SalePrice],
		[Quantity],
		[GST],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[IsNewArrival],
		[IsHotProduct],
		[Thumbnail],
		[IsHomeProduct],
		[IsDealerOnly],
		[SoldQuantity],
		[RegularPrice],
		[BranchID],
		[StockKey],
		[PartnerPrice]
	FROM [Products]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductsUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsUpdate];
GO

CREATE PROCEDURE [proc_ProductsUpdate]
(
	@ID int,
	@ProductName nvarchar(50) = NULL,
	@CategoryID int = NULL,
	@IMEIAvailable bit = NULL,
	@BrandID int = NULL,
	@Description ntext = NULL,
	@Picture nvarchar(500) = NULL,
	@BarCode nvarchar(50) = NULL,
	@Cost numeric(18,2) = NULL,
	@DealerPrice numeric(18,2) = NULL,
	@SalePrice numeric(18,2) = NULL,
	@Quantity int = NULL,
	@GST bit = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@IsNewArrival bit = NULL,
	@IsHotProduct bit = NULL,
	@Thumbnail nvarchar(500) = NULL,
	@IsHomeProduct bit = NULL,
	@IsDealerOnly bit = NULL,
	@SoldQuantity int = NULL,
	@RegularPrice numeric(18,2) = NULL,
	@BranchID int,
	@StockKey int = NULL,
	@PartnerPrice numeric(18,2) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Products]
	SET
		[ProductName] = @ProductName,
		[CategoryID] = @CategoryID,
		[IMEIAvailable] = @IMEIAvailable,
		[BrandID] = @BrandID,
		[Description] = @Description,
		[Picture] = @Picture,
		[BarCode] = @BarCode,
		[Cost] = @Cost,
		[DealerPrice] = @DealerPrice,
		[SalePrice] = @SalePrice,
		[Quantity] = @Quantity,
		[GST] = @GST,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[IsNewArrival] = @IsNewArrival,
		[IsHotProduct] = @IsHotProduct,
		[Thumbnail] = @Thumbnail,
		[IsHomeProduct] = @IsHomeProduct,
		[IsDealerOnly] = @IsDealerOnly,
		[SoldQuantity] = @SoldQuantity,
		[RegularPrice] = @RegularPrice,
		[BranchID] = @BranchID,
		[StockKey] = @StockKey,
		[PartnerPrice] = @PartnerPrice
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ProductsInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsInsert];
GO

CREATE PROCEDURE [proc_ProductsInsert]
(
	@ID int = NULL output,
	@ProductName nvarchar(50) = NULL,
	@CategoryID int = NULL,
	@IMEIAvailable bit = NULL,
	@BrandID int = NULL,
	@Description ntext = NULL,
	@Picture nvarchar(500) = NULL,
	@BarCode nvarchar(50) = NULL,
	@Cost numeric(18,2) = NULL,
	@DealerPrice numeric(18,2) = NULL,
	@SalePrice numeric(18,2) = NULL,
	@Quantity int = NULL,
	@GST bit = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@IsNewArrival bit = NULL,
	@IsHotProduct bit = NULL,
	@Thumbnail nvarchar(500) = NULL,
	@IsHomeProduct bit = NULL,
	@IsDealerOnly bit = NULL,
	@SoldQuantity int = NULL,
	@RegularPrice numeric(18,2) = NULL,
	@BranchID int,
	@StockKey int = NULL,
	@PartnerPrice numeric(18,2) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Products]
	(
		[ProductName],
		[CategoryID],
		[IMEIAvailable],
		[BrandID],
		[Description],
		[Picture],
		[BarCode],
		[Cost],
		[DealerPrice],
		[SalePrice],
		[Quantity],
		[GST],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[IsNewArrival],
		[IsHotProduct],
		[Thumbnail],
		[IsHomeProduct],
		[IsDealerOnly],
		[SoldQuantity],
		[RegularPrice],
		[BranchID],
		[StockKey],
		[PartnerPrice]
	)
	VALUES
	(
		@ProductName,
		@CategoryID,
		@IMEIAvailable,
		@BrandID,
		@Description,
		@Picture,
		@BarCode,
		@Cost,
		@DealerPrice,
		@SalePrice,
		@Quantity,
		@GST,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@IsNewArrival,
		@IsHotProduct,
		@Thumbnail,
		@IsHomeProduct,
		@IsDealerOnly,
		@SoldQuantity,
		@RegularPrice,
		@BranchID,
		@StockKey,
		@PartnerPrice
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductsDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductsDelete];
GO

CREATE PROCEDURE [proc_ProductsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Products]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductStatusesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductStatusesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductStatusesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ProductStatusesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[StatusName]
	FROM [ProductStatuses]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductStatusesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductStatusesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductStatusesLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductStatusesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductStatusesLoadAll];
GO

CREATE PROCEDURE [proc_ProductStatusesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[StatusName]
	FROM [ProductStatuses]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductStatusesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductStatusesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductStatusesUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductStatusesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductStatusesUpdate];
GO

CREATE PROCEDURE [proc_ProductStatusesUpdate]
(
	@ID int,
	@StatusName nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [ProductStatuses]
	SET
		[StatusName] = @StatusName
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductStatusesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductStatusesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ProductStatusesInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductStatusesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductStatusesInsert];
GO

CREATE PROCEDURE [proc_ProductStatusesInsert]
(
	@ID int,
	@StatusName nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [ProductStatuses]
	(
		[ID],
		[StatusName]
	)
	VALUES
	(
		@ID,
		@StatusName
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductStatusesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductStatusesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductStatusesDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductStatusesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductStatusesDelete];
GO

CREATE PROCEDURE [proc_ProductStatusesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [ProductStatuses]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductStatusesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductStatusesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductTagsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductTagsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductTagsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ProductTagsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductID],
		[Tag]
	FROM [ProductTags]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductTagsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductTagsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductTagsLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductTagsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductTagsLoadAll];
GO

CREATE PROCEDURE [proc_ProductTagsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[ProductID],
		[Tag]
	FROM [ProductTags]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductTagsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductTagsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductTagsUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductTagsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductTagsUpdate];
GO

CREATE PROCEDURE [proc_ProductTagsUpdate]
(
	@ID int,
	@ProductID int,
	@Tag nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [ProductTags]
	SET
		[ProductID] = @ProductID,
		[Tag] = @Tag
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductTagsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductTagsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ProductTagsInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductTagsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductTagsInsert];
GO

CREATE PROCEDURE [proc_ProductTagsInsert]
(
	@ID int = NULL output,
	@ProductID int,
	@Tag nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [ProductTags]
	(
		[ProductID],
		[Tag]
	)
	VALUES
	(
		@ProductID,
		@Tag
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductTagsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductTagsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ProductTagsDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ProductTagsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ProductTagsDelete];
GO

CREATE PROCEDURE [proc_ProductTagsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [ProductTags]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ProductTagsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ProductTagsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchaseOrderDetailsLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrderDetailsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrderDetailsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_PurchaseOrderDetailsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[PurchaseOrderID],
		[ProductID],
		[IMEI],
		[Description],
		[Quantity],
		[GST],
		[UnitPrice],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [PurchaseOrderDetails]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrderDetailsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrderDetailsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchaseOrderDetailsLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrderDetailsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrderDetailsLoadAll];
GO

CREATE PROCEDURE [proc_PurchaseOrderDetailsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[PurchaseOrderID],
		[ProductID],
		[IMEI],
		[Description],
		[Quantity],
		[GST],
		[UnitPrice],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [PurchaseOrderDetails]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrderDetailsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrderDetailsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchaseOrderDetailsUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrderDetailsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrderDetailsUpdate];
GO

CREATE PROCEDURE [proc_PurchaseOrderDetailsUpdate]
(
	@ID int,
	@PurchaseOrderID int = NULL,
	@ProductID int = NULL,
	@IMEI nvarchar(20) = NULL,
	@Description nvarchar(500) = NULL,
	@Quantity int = NULL,
	@GST numeric(18,2) = NULL,
	@UnitPrice numeric(18,2) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [PurchaseOrderDetails]
	SET
		[PurchaseOrderID] = @PurchaseOrderID,
		[ProductID] = @ProductID,
		[IMEI] = @IMEI,
		[Description] = @Description,
		[Quantity] = @Quantity,
		[GST] = @GST,
		[UnitPrice] = @UnitPrice,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrderDetailsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrderDetailsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_PurchaseOrderDetailsInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrderDetailsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrderDetailsInsert];
GO

CREATE PROCEDURE [proc_PurchaseOrderDetailsInsert]
(
	@ID int = NULL output,
	@PurchaseOrderID int = NULL,
	@ProductID int = NULL,
	@IMEI nvarchar(20) = NULL,
	@Description nvarchar(500) = NULL,
	@Quantity int = NULL,
	@GST numeric(18,2) = NULL,
	@UnitPrice numeric(18,2) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [PurchaseOrderDetails]
	(
		[PurchaseOrderID],
		[ProductID],
		[IMEI],
		[Description],
		[Quantity],
		[GST],
		[UnitPrice],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	)
	VALUES
	(
		@PurchaseOrderID,
		@ProductID,
		@IMEI,
		@Description,
		@Quantity,
		@GST,
		@UnitPrice,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrderDetailsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrderDetailsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchaseOrderDetailsDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrderDetailsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrderDetailsDelete];
GO

CREATE PROCEDURE [proc_PurchaseOrderDetailsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [PurchaseOrderDetails]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrderDetailsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrderDetailsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchaseOrdersLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrdersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrdersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_PurchaseOrdersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[PurchaseOrderNo],
		[InvoiceNo],
		[SupplierID],
		[GSTTotalAmount],
		[TotalAmount],
		[PaidAmount],
		[CreatedDate],
		[CreatedByUser],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[BranchID]
	FROM [PurchaseOrders]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrdersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrdersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchaseOrdersLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrdersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrdersLoadAll];
GO

CREATE PROCEDURE [proc_PurchaseOrdersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[PurchaseOrderNo],
		[InvoiceNo],
		[SupplierID],
		[GSTTotalAmount],
		[TotalAmount],
		[PaidAmount],
		[CreatedDate],
		[CreatedByUser],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[BranchID]
	FROM [PurchaseOrders]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrdersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrdersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchaseOrdersUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrdersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrdersUpdate];
GO

CREATE PROCEDURE [proc_PurchaseOrdersUpdate]
(
	@ID int,
	@PurchaseOrderNo char(10) = NULL,
	@InvoiceNo nvarchar(20) = NULL,
	@SupplierID int = NULL,
	@GSTTotalAmount numeric(18,2) = NULL,
	@TotalAmount numeric(18,2) = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@CreatedDate datetime = NULL,
	@CreatedByUser int = NULL,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [PurchaseOrders]
	SET
		[PurchaseOrderNo] = @PurchaseOrderNo,
		[InvoiceNo] = @InvoiceNo,
		[SupplierID] = @SupplierID,
		[GSTTotalAmount] = @GSTTotalAmount,
		[TotalAmount] = @TotalAmount,
		[PaidAmount] = @PaidAmount,
		[CreatedDate] = @CreatedDate,
		[CreatedByUser] = @CreatedByUser,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Deleted] = @Deleted,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrdersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrdersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_PurchaseOrdersInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrdersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrdersInsert];
GO

CREATE PROCEDURE [proc_PurchaseOrdersInsert]
(
	@ID int = NULL output,
	@PurchaseOrderNo char(10) = NULL,
	@InvoiceNo nvarchar(20) = NULL,
	@SupplierID int = NULL,
	@GSTTotalAmount numeric(18,2) = NULL,
	@TotalAmount numeric(18,2) = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@CreatedDate datetime = NULL,
	@CreatedByUser int = NULL,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [PurchaseOrders]
	(
		[PurchaseOrderNo],
		[InvoiceNo],
		[SupplierID],
		[GSTTotalAmount],
		[TotalAmount],
		[PaidAmount],
		[CreatedDate],
		[CreatedByUser],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[BranchID]
	)
	VALUES
	(
		@PurchaseOrderNo,
		@InvoiceNo,
		@SupplierID,
		@GSTTotalAmount,
		@TotalAmount,
		@PaidAmount,
		@CreatedDate,
		@CreatedByUser,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Deleted,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrdersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrdersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchaseOrdersDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchaseOrdersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchaseOrdersDelete];
GO

CREATE PROCEDURE [proc_PurchaseOrdersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [PurchaseOrders]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchaseOrdersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchaseOrdersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchasePaymentHistoriesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchasePaymentHistoriesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchasePaymentHistoriesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_PurchasePaymentHistoriesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[PurchaseOrderID],
		[PaymentMethodID],
		[PaidAmount],
		[PaidDate],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [PurchasePaymentHistories]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchasePaymentHistoriesLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchasePaymentHistoriesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchasePaymentHistoriesLoadAll];
GO

CREATE PROCEDURE [proc_PurchasePaymentHistoriesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[PurchaseOrderID],
		[PaymentMethodID],
		[PaidAmount],
		[PaidDate],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [PurchasePaymentHistories]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchasePaymentHistoriesUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchasePaymentHistoriesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchasePaymentHistoriesUpdate];
GO

CREATE PROCEDURE [proc_PurchasePaymentHistoriesUpdate]
(
	@ID int,
	@PurchaseOrderID int = NULL,
	@PaymentMethodID int = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@PaidDate datetime = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [PurchasePaymentHistories]
	SET
		[PurchaseOrderID] = @PurchaseOrderID,
		[PaymentMethodID] = @PaymentMethodID,
		[PaidAmount] = @PaidAmount,
		[PaidDate] = @PaidDate,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_PurchasePaymentHistoriesInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchasePaymentHistoriesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchasePaymentHistoriesInsert];
GO

CREATE PROCEDURE [proc_PurchasePaymentHistoriesInsert]
(
	@ID int = NULL output,
	@PurchaseOrderID int = NULL,
	@PaymentMethodID int = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@PaidDate datetime = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [PurchasePaymentHistories]
	(
		[PurchaseOrderID],
		[PaymentMethodID],
		[PaidAmount],
		[PaidDate],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	)
	VALUES
	(
		@PurchaseOrderID,
		@PaymentMethodID,
		@PaidAmount,
		@PaidDate,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_PurchasePaymentHistoriesDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_PurchasePaymentHistoriesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_PurchasePaymentHistoriesDelete];
GO

CREATE PROCEDURE [proc_PurchasePaymentHistoriesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [PurchasePaymentHistories]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_PurchasePaymentHistoriesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RelatedLinksLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RelatedLinksLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RelatedLinksLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RelatedLinksLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Title],
		[Description],
		[URL]
	FROM [RelatedLinks]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RelatedLinksLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RelatedLinksLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RelatedLinksLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RelatedLinksLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RelatedLinksLoadAll];
GO

CREATE PROCEDURE [proc_RelatedLinksLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Title],
		[Description],
		[URL]
	FROM [RelatedLinks]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RelatedLinksLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RelatedLinksLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RelatedLinksUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RelatedLinksUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RelatedLinksUpdate];
GO

CREATE PROCEDURE [proc_RelatedLinksUpdate]
(
	@ID int,
	@Title nvarchar(50),
	@Description nvarchar(150) = NULL,
	@URL nvarchar(MAX)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RelatedLinks]
	SET
		[Title] = @Title,
		[Description] = @Description,
		[URL] = @URL
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RelatedLinksUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RelatedLinksUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RelatedLinksInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RelatedLinksInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RelatedLinksInsert];
GO

CREATE PROCEDURE [proc_RelatedLinksInsert]
(
	@ID int = NULL output,
	@Title nvarchar(50),
	@Description nvarchar(150) = NULL,
	@URL nvarchar(MAX)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RelatedLinks]
	(
		[Title],
		[Description],
		[URL]
	)
	VALUES
	(
		@Title,
		@Description,
		@URL
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RelatedLinksInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RelatedLinksInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RelatedLinksDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RelatedLinksDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RelatedLinksDelete];
GO

CREATE PROCEDURE [proc_RelatedLinksDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RelatedLinks]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RelatedLinksDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RelatedLinksDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairAccessoryLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairAccessoryLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairAccessoryLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairAccessoryLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[AccessoryName],
		[Deleted]
	FROM [RepairAccessory]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairAccessoryLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairAccessoryLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairAccessoryLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairAccessoryLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairAccessoryLoadAll];
GO

CREATE PROCEDURE [proc_RepairAccessoryLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[AccessoryName],
		[Deleted]
	FROM [RepairAccessory]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairAccessoryLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairAccessoryLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairAccessoryUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairAccessoryUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairAccessoryUpdate];
GO

CREATE PROCEDURE [proc_RepairAccessoryUpdate]
(
	@ID int,
	@AccessoryName nvarchar(50) = NULL,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RepairAccessory]
	SET
		[AccessoryName] = @AccessoryName,
		[Deleted] = @Deleted
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairAccessoryUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairAccessoryUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RepairAccessoryInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairAccessoryInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairAccessoryInsert];
GO

CREATE PROCEDURE [proc_RepairAccessoryInsert]
(
	@ID int = NULL output,
	@AccessoryName nvarchar(50) = NULL,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairAccessory]
	(
		[AccessoryName],
		[Deleted]
	)
	VALUES
	(
		@AccessoryName,
		@Deleted
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairAccessoryInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairAccessoryInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairAccessoryDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairAccessoryDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairAccessoryDelete];
GO

CREATE PROCEDURE [proc_RepairAccessoryDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairAccessory]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairAccessoryDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairAccessoryDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairBoxesLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairBoxesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairBoxesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairBoxesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairBoxName],
		[IsFree],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[BranchID]
	FROM [RepairBoxes]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairBoxesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairBoxesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairBoxesLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairBoxesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairBoxesLoadAll];
GO

CREATE PROCEDURE [proc_RepairBoxesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairBoxName],
		[IsFree],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[BranchID]
	FROM [RepairBoxes]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairBoxesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairBoxesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairBoxesUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairBoxesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairBoxesUpdate];
GO

CREATE PROCEDURE [proc_RepairBoxesUpdate]
(
	@ID int,
	@RepairBoxName nvarchar(50),
	@IsFree bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RepairBoxes]
	SET
		[RepairBoxName] = @RepairBoxName,
		[IsFree] = @IsFree,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Deleted] = @Deleted,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairBoxesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairBoxesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RepairBoxesInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairBoxesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairBoxesInsert];
GO

CREATE PROCEDURE [proc_RepairBoxesInsert]
(
	@ID int = NULL output,
	@RepairBoxName nvarchar(50),
	@IsFree bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Deleted bit,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairBoxes]
	(
		[RepairBoxName],
		[IsFree],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Deleted],
		[BranchID]
	)
	VALUES
	(
		@RepairBoxName,
		@IsFree,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Deleted,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairBoxesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairBoxesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairBoxesDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairBoxesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairBoxesDelete];
GO

CREATE PROCEDURE [proc_RepairBoxesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairBoxes]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairBoxesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairBoxesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobLoadByPrimaryKey]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairJobLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairNo],
		[RepairModelID],
		[IMEI],
		[StatusID],
		[Note],
		[Accessories],
		[CustomerID],
		[CustomerName],
		[CustomerPhone],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[CreatedDate],
		[CreatedByUser],
		[InvoiceID],
		[IsRetail],
		[IsRedo],
		[RepairBoxID],
		[PreviousStatusID],
		[LoanPhoneID],
		[LoanPhoneReturn],
		[BranchID],
		[InvoiceDetailID]
	FROM [RepairJob]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobLoadAll]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobLoadAll];
GO

CREATE PROCEDURE [proc_RepairJobLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairNo],
		[RepairModelID],
		[IMEI],
		[StatusID],
		[Note],
		[Accessories],
		[CustomerID],
		[CustomerName],
		[CustomerPhone],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[CreatedDate],
		[CreatedByUser],
		[InvoiceID],
		[IsRetail],
		[IsRedo],
		[RepairBoxID],
		[PreviousStatusID],
		[LoanPhoneID],
		[LoanPhoneReturn],
		[BranchID],
		[InvoiceDetailID]
	FROM [RepairJob]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobUpdate]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobUpdate];
GO

CREATE PROCEDURE [proc_RepairJobUpdate]
(
	@ID int,
	@RepairNo char(10),
	@RepairModelID int,
	@IMEI nvarchar(20),
	@StatusID int = NULL,
	@Note nvarchar(MAX) = NULL,
	@Accessories nvarchar(100) = NULL,
	@CustomerID int = NULL,
	@CustomerName nvarchar(50) = NULL,
	@CustomerPhone nvarchar(20),
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@CreatedDate datetime,
	@CreatedByUser int,
	@InvoiceID int = NULL,
	@IsRetail bit = NULL,
	@IsRedo bit = NULL,
	@RepairBoxID int = NULL,
	@PreviousStatusID int = NULL,
	@LoanPhoneID int = NULL,
	@LoanPhoneReturn bit = NULL,
	@BranchID int,
	@InvoiceDetailID int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RepairJob]
	SET
		[RepairNo] = @RepairNo,
		[RepairModelID] = @RepairModelID,
		[IMEI] = @IMEI,
		[StatusID] = @StatusID,
		[Note] = @Note,
		[Accessories] = @Accessories,
		[CustomerID] = @CustomerID,
		[CustomerName] = @CustomerName,
		[CustomerPhone] = @CustomerPhone,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[CreatedDate] = @CreatedDate,
		[CreatedByUser] = @CreatedByUser,
		[InvoiceID] = @InvoiceID,
		[IsRetail] = @IsRetail,
		[IsRedo] = @IsRedo,
		[RepairBoxID] = @RepairBoxID,
		[PreviousStatusID] = @PreviousStatusID,
		[LoanPhoneID] = @LoanPhoneID,
		[LoanPhoneReturn] = @LoanPhoneReturn,
		[BranchID] = @BranchID,
		[InvoiceDetailID] = @InvoiceDetailID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RepairJobInsert]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobInsert];
GO

CREATE PROCEDURE [proc_RepairJobInsert]
(
	@ID int = NULL output,
	@RepairNo char(10),
	@RepairModelID int,
	@IMEI nvarchar(20),
	@StatusID int = NULL,
	@Note nvarchar(MAX) = NULL,
	@Accessories nvarchar(100) = NULL,
	@CustomerID int = NULL,
	@CustomerName nvarchar(50) = NULL,
	@CustomerPhone nvarchar(20),
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@CreatedDate datetime,
	@CreatedByUser int,
	@InvoiceID int = NULL,
	@IsRetail bit = NULL,
	@IsRedo bit = NULL,
	@RepairBoxID int = NULL,
	@PreviousStatusID int = NULL,
	@LoanPhoneID int = NULL,
	@LoanPhoneReturn bit = NULL,
	@BranchID int,
	@InvoiceDetailID int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairJob]
	(
		[RepairNo],
		[RepairModelID],
		[IMEI],
		[StatusID],
		[Note],
		[Accessories],
		[CustomerID],
		[CustomerName],
		[CustomerPhone],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[CreatedDate],
		[CreatedByUser],
		[InvoiceID],
		[IsRetail],
		[IsRedo],
		[RepairBoxID],
		[PreviousStatusID],
		[LoanPhoneID],
		[LoanPhoneReturn],
		[BranchID],
		[InvoiceDetailID]
	)
	VALUES
	(
		@RepairNo,
		@RepairModelID,
		@IMEI,
		@StatusID,
		@Note,
		@Accessories,
		@CustomerID,
		@CustomerName,
		@CustomerPhone,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@CreatedDate,
		@CreatedByUser,
		@InvoiceID,
		@IsRetail,
		@IsRedo,
		@RepairBoxID,
		@PreviousStatusID,
		@LoanPhoneID,
		@LoanPhoneReturn,
		@BranchID,
		@InvoiceDetailID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobDelete]    Script Date: 9/17/2011 5:25:59 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobDelete];
GO

CREATE PROCEDURE [proc_RepairJobDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairJob]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobAccessoryLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobAccessoryLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobAccessoryLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairJobAccessoryLoadByPrimaryKey]
(
	@RepairJobID int,
	@AccessoryID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[RepairJobID],
		[AccessoryID]
	FROM [RepairJobAccessory]
	WHERE
		([RepairJobID] = @RepairJobID) AND
		([AccessoryID] = @AccessoryID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobAccessoryLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobAccessoryLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobAccessoryLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobAccessoryLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobAccessoryLoadAll];
GO

CREATE PROCEDURE [proc_RepairJobAccessoryLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[RepairJobID],
		[AccessoryID]
	FROM [RepairJobAccessory]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobAccessoryLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobAccessoryLoadAll Error on Creation'
GO

-------------------------------------------
-- NO UPDATE Stored Procedure Generated    
-- All Columns are part of the Primary key 
-------------------------------------------


/****** Object:  StoredProcedure [proc_RepairJobAccessoryInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobAccessoryInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobAccessoryInsert];
GO

CREATE PROCEDURE [proc_RepairJobAccessoryInsert]
(
	@RepairJobID int = NULL output,
	@AccessoryID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairJobAccessory]
	(
		[AccessoryID]
	)
	VALUES
	(
		@AccessoryID
	)

	SET @Err = @@Error

	SELECT @RepairJobID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobAccessoryInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobAccessoryInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobAccessoryDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobAccessoryDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobAccessoryDelete];
GO

CREATE PROCEDURE [proc_RepairJobAccessoryDelete]
(
	@RepairJobID int,
	@AccessoryID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairJobAccessory]
	WHERE
		[RepairJobID] = @RepairJobID AND
		[AccessoryID] = @AccessoryID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobAccessoryDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobAccessoryDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobProblemsLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobProblemsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobProblemsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairJobProblemsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairJobID],
		[RepairModelProblemID],
		[Description],
		[Price],
		[PreviousPrice],
		[BranchID]
	FROM [RepairJobProblems]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobProblemsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobProblemsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobProblemsLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobProblemsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobProblemsLoadAll];
GO

CREATE PROCEDURE [proc_RepairJobProblemsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairJobID],
		[RepairModelProblemID],
		[Description],
		[Price],
		[PreviousPrice],
		[BranchID]
	FROM [RepairJobProblems]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobProblemsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobProblemsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobProblemsUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobProblemsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobProblemsUpdate];
GO

CREATE PROCEDURE [proc_RepairJobProblemsUpdate]
(
	@ID int,
	@RepairJobID int,
	@RepairModelProblemID int,
	@Description nvarchar(100),
	@Price numeric(18,2),
	@PreviousPrice numeric(18,2) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RepairJobProblems]
	SET
		[RepairJobID] = @RepairJobID,
		[RepairModelProblemID] = @RepairModelProblemID,
		[Description] = @Description,
		[Price] = @Price,
		[PreviousPrice] = @PreviousPrice,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobProblemsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobProblemsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RepairJobProblemsInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobProblemsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobProblemsInsert];
GO

CREATE PROCEDURE [proc_RepairJobProblemsInsert]
(
	@ID int = NULL output,
	@RepairJobID int,
	@RepairModelProblemID int,
	@Description nvarchar(100),
	@Price numeric(18,2),
	@PreviousPrice numeric(18,2) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairJobProblems]
	(
		[RepairJobID],
		[RepairModelProblemID],
		[Description],
		[Price],
		[PreviousPrice],
		[BranchID]
	)
	VALUES
	(
		@RepairJobID,
		@RepairModelProblemID,
		@Description,
		@Price,
		@PreviousPrice,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobProblemsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobProblemsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairJobProblemsDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairJobProblemsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairJobProblemsDelete];
GO

CREATE PROCEDURE [proc_RepairJobProblemsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairJobProblems]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairJobProblemsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairJobProblemsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairModelProblemsLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelProblemsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelProblemsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairModelProblemsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairModelID],
		[ProblemID],
		[RPP],
		[StandardPrice],
		[SpecialPrice],
		[BranchID]
	FROM [RepairModelProblems]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelProblemsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelProblemsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairModelProblemsLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelProblemsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelProblemsLoadAll];
GO

CREATE PROCEDURE [proc_RepairModelProblemsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairModelID],
		[ProblemID],
		[RPP],
		[StandardPrice],
		[SpecialPrice],
		[BranchID]
	FROM [RepairModelProblems]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelProblemsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelProblemsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairModelProblemsUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelProblemsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelProblemsUpdate];
GO

CREATE PROCEDURE [proc_RepairModelProblemsUpdate]
(
	@ID int,
	@RepairModelID int,
	@ProblemID int,
	@RPP numeric(18,2) = NULL,
	@StandardPrice numeric(18,2) = NULL,
	@SpecialPrice numeric(18,2) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RepairModelProblems]
	SET
		[RepairModelID] = @RepairModelID,
		[ProblemID] = @ProblemID,
		[RPP] = @RPP,
		[StandardPrice] = @StandardPrice,
		[SpecialPrice] = @SpecialPrice,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelProblemsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelProblemsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RepairModelProblemsInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelProblemsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelProblemsInsert];
GO

CREATE PROCEDURE [proc_RepairModelProblemsInsert]
(
	@ID int = NULL output,
	@RepairModelID int,
	@ProblemID int,
	@RPP numeric(18,2) = NULL,
	@StandardPrice numeric(18,2) = NULL,
	@SpecialPrice numeric(18,2) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairModelProblems]
	(
		[RepairModelID],
		[ProblemID],
		[RPP],
		[StandardPrice],
		[SpecialPrice],
		[BranchID]
	)
	VALUES
	(
		@RepairModelID,
		@ProblemID,
		@RPP,
		@StandardPrice,
		@SpecialPrice,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelProblemsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelProblemsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairModelProblemsDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelProblemsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelProblemsDelete];
GO

CREATE PROCEDURE [proc_RepairModelProblemsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairModelProblems]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelProblemsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelProblemsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairModelsLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairModelsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[BrandID],
		[ModelName],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [RepairModels]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairModelsLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelsLoadAll];
GO

CREATE PROCEDURE [proc_RepairModelsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[BrandID],
		[ModelName],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [RepairModels]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairModelsUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelsUpdate];
GO

CREATE PROCEDURE [proc_RepairModelsUpdate]
(
	@ID int,
	@BrandID int,
	@ModelName nvarchar(50) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RepairModels]
	SET
		[BrandID] = @BrandID,
		[ModelName] = @ModelName,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RepairModelsInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelsInsert];
GO

CREATE PROCEDURE [proc_RepairModelsInsert]
(
	@ID int = NULL output,
	@BrandID int,
	@ModelName nvarchar(50) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairModels]
	(
		[BrandID],
		[ModelName],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	)
	VALUES
	(
		@BrandID,
		@ModelName,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairModelsDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairModelsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairModelsDelete];
GO

CREATE PROCEDURE [proc_RepairModelsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairModels]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairModelsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairModelsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairStatusLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[StatusName],
		[Deleted]
	FROM [RepairStatus]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusLoadAll];
GO

CREATE PROCEDURE [proc_RepairStatusLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[StatusName],
		[Deleted]
	FROM [RepairStatus]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusUpdate];
GO

CREATE PROCEDURE [proc_RepairStatusUpdate]
(
	@ID int,
	@StatusName nvarchar(50),
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RepairStatus]
	SET
		[StatusName] = @StatusName,
		[Deleted] = @Deleted
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RepairStatusInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusInsert];
GO

CREATE PROCEDURE [proc_RepairStatusInsert]
(
	@ID int,
	@StatusName nvarchar(50),
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairStatus]
	(
		[ID],
		[StatusName],
		[Deleted]
	)
	VALUES
	(
		@ID,
		@StatusName,
		@Deleted
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusDelete];
GO

CREATE PROCEDURE [proc_RepairStatusDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairStatus]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusDetailsLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusDetailsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusDetailsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairStatusDetailsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairStatusID],
		[Description]
	FROM [RepairStatusDetails]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusDetailsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusDetailsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusDetailsLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusDetailsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusDetailsLoadAll];
GO

CREATE PROCEDURE [proc_RepairStatusDetailsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairStatusID],
		[Description]
	FROM [RepairStatusDetails]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusDetailsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusDetailsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusDetailsUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusDetailsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusDetailsUpdate];
GO

CREATE PROCEDURE [proc_RepairStatusDetailsUpdate]
(
	@ID int,
	@RepairStatusID int,
	@Description nvarchar(100)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RepairStatusDetails]
	SET
		[RepairStatusID] = @RepairStatusID,
		[Description] = @Description
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusDetailsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusDetailsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RepairStatusDetailsInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusDetailsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusDetailsInsert];
GO

CREATE PROCEDURE [proc_RepairStatusDetailsInsert]
(
	@ID int = NULL output,
	@RepairStatusID int,
	@Description nvarchar(100)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairStatusDetails]
	(
		[RepairStatusID],
		[Description]
	)
	VALUES
	(
		@RepairStatusID,
		@Description
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusDetailsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusDetailsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusDetailsDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusDetailsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusDetailsDelete];
GO

CREATE PROCEDURE [proc_RepairStatusDetailsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairStatusDetails]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusDetailsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusDetailsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusHistoriesLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusHistoriesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusHistoriesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RepairStatusHistoriesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairJobID],
		[RepairStatusID],
		[UpdatedDate],
		[UpdatedByUser],
		[UpdatedByCustomer],
		[BranchID]
	FROM [RepairStatusHistories]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusHistoriesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusHistoriesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusHistoriesLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusHistoriesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusHistoriesLoadAll];
GO

CREATE PROCEDURE [proc_RepairStatusHistoriesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RepairJobID],
		[RepairStatusID],
		[UpdatedDate],
		[UpdatedByUser],
		[UpdatedByCustomer],
		[BranchID]
	FROM [RepairStatusHistories]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusHistoriesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusHistoriesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusHistoriesUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusHistoriesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusHistoriesUpdate];
GO

CREATE PROCEDURE [proc_RepairStatusHistoriesUpdate]
(
	@ID int,
	@RepairJobID int,
	@RepairStatusID int,
	@UpdatedDate datetime,
	@UpdatedByUser int = NULL,
	@UpdatedByCustomer int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [RepairStatusHistories]
	SET
		[RepairJobID] = @RepairJobID,
		[RepairStatusID] = @RepairStatusID,
		[UpdatedDate] = @UpdatedDate,
		[UpdatedByUser] = @UpdatedByUser,
		[UpdatedByCustomer] = @UpdatedByCustomer,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusHistoriesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusHistoriesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RepairStatusHistoriesInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusHistoriesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusHistoriesInsert];
GO

CREATE PROCEDURE [proc_RepairStatusHistoriesInsert]
(
	@ID int = NULL output,
	@RepairJobID int,
	@RepairStatusID int,
	@UpdatedDate datetime,
	@UpdatedByUser int = NULL,
	@UpdatedByCustomer int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [RepairStatusHistories]
	(
		[RepairJobID],
		[RepairStatusID],
		[UpdatedDate],
		[UpdatedByUser],
		[UpdatedByCustomer],
		[BranchID]
	)
	VALUES
	(
		@RepairJobID,
		@RepairStatusID,
		@UpdatedDate,
		@UpdatedByUser,
		@UpdatedByCustomer,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusHistoriesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusHistoriesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RepairStatusHistoriesDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RepairStatusHistoriesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RepairStatusHistoriesDelete];
GO

CREATE PROCEDURE [proc_RepairStatusHistoriesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [RepairStatusHistories]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RepairStatusHistoriesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RepairStatusHistoriesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RolesLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RolesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RolesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_RolesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RoleName],
		[Products],
		[Sales],
		[Purchase],
		[Customers],
		[Suppliers],
		[Repair],
		[Report],
		[Admin],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Contracts],
		[BranchID],
		[SystemAdmin],
		[EditSales],
		[Expense]
	FROM [Roles]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RolesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_RolesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RolesLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RolesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RolesLoadAll];
GO

CREATE PROCEDURE [proc_RolesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[RoleName],
		[Products],
		[Sales],
		[Purchase],
		[Customers],
		[Suppliers],
		[Repair],
		[Report],
		[Admin],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Contracts],
		[BranchID],
		[SystemAdmin],
		[EditSales],
		[Expense]
	FROM [Roles]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RolesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_RolesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RolesUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RolesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RolesUpdate];
GO

CREATE PROCEDURE [proc_RolesUpdate]
(
	@ID int,
	@RoleName nchar(10),
	@Products bit,
	@Sales bit,
	@Purchase bit,
	@Customers bit,
	@Suppliers bit,
	@Repair bit,
	@Report bit,
	@Admin bit,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Contracts bit,
	@BranchID int,
	@SystemAdmin bit = NULL,
	@EditSales bit = NULL,
	@Expense bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Roles]
	SET
		[RoleName] = @RoleName,
		[Products] = @Products,
		[Sales] = @Sales,
		[Purchase] = @Purchase,
		[Customers] = @Customers,
		[Suppliers] = @Suppliers,
		[Repair] = @Repair,
		[Report] = @Report,
		[Admin] = @Admin,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Contracts] = @Contracts,
		[BranchID] = @BranchID,
		[SystemAdmin] = @SystemAdmin,
		[EditSales] = @EditSales,
		[Expense] = @Expense
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RolesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_RolesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_RolesInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RolesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RolesInsert];
GO

CREATE PROCEDURE [proc_RolesInsert]
(
	@ID int = NULL output,
	@RoleName nchar(10),
	@Products bit,
	@Sales bit,
	@Purchase bit,
	@Customers bit,
	@Suppliers bit,
	@Repair bit,
	@Report bit,
	@Admin bit,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Contracts bit,
	@BranchID int,
	@SystemAdmin bit = NULL,
	@EditSales bit = NULL,
	@Expense bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Roles]
	(
		[RoleName],
		[Products],
		[Sales],
		[Purchase],
		[Customers],
		[Suppliers],
		[Repair],
		[Report],
		[Admin],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Contracts],
		[BranchID],
		[SystemAdmin],
		[EditSales],
		[Expense]
	)
	VALUES
	(
		@RoleName,
		@Products,
		@Sales,
		@Purchase,
		@Customers,
		@Suppliers,
		@Repair,
		@Report,
		@Admin,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Contracts,
		@BranchID,
		@SystemAdmin,
		@EditSales,
		@Expense
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RolesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_RolesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_RolesDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_RolesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_RolesDelete];
GO

CREATE PROCEDURE [proc_RolesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Roles]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_RolesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_RolesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SequenceLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SequenceLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SequenceLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_SequenceLoadByPrimaryKey]
(
	@SeqKey nvarchar(50)
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[SeqKey],
		[SeqValue],
		[SeqDate],
		[SeqLength]
	FROM [Sequence]
	WHERE
		([SeqKey] = @SeqKey)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SequenceLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_SequenceLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SequenceLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SequenceLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SequenceLoadAll];
GO

CREATE PROCEDURE [proc_SequenceLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[SeqKey],
		[SeqValue],
		[SeqDate],
		[SeqLength]
	FROM [Sequence]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SequenceLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_SequenceLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SequenceUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SequenceUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SequenceUpdate];
GO

CREATE PROCEDURE [proc_SequenceUpdate]
(
	@SeqKey nvarchar(50),
	@SeqValue int = NULL,
	@SeqDate datetime = NULL,
	@SeqLength int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Sequence]
	SET
		[SeqValue] = @SeqValue,
		[SeqDate] = @SeqDate,
		[SeqLength] = @SeqLength
	WHERE
		[SeqKey] = @SeqKey


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SequenceUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_SequenceUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_SequenceInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SequenceInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SequenceInsert];
GO

CREATE PROCEDURE [proc_SequenceInsert]
(
	@SeqKey nvarchar(50),
	@SeqValue int = NULL,
	@SeqDate datetime = NULL,
	@SeqLength int = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Sequence]
	(
		[SeqKey],
		[SeqValue],
		[SeqDate],
		[SeqLength]
	)
	VALUES
	(
		@SeqKey,
		@SeqValue,
		@SeqDate,
		@SeqLength
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SequenceInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_SequenceInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SequenceDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SequenceDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SequenceDelete];
GO

CREATE PROCEDURE [proc_SequenceDelete]
(
	@SeqKey nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Sequence]
	WHERE
		[SeqKey] = @SeqKey
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SequenceDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_SequenceDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ShortAdLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ShortAdLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ShortAdLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_ShortAdLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Content],
		[LastModifiedDate],
		[Selected],
		[Deleted],
		[DealerOnly]
	FROM [ShortAd]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ShortAdLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_ShortAdLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ShortAdLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ShortAdLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ShortAdLoadAll];
GO

CREATE PROCEDURE [proc_ShortAdLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Content],
		[LastModifiedDate],
		[Selected],
		[Deleted],
		[DealerOnly]
	FROM [ShortAd]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ShortAdLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_ShortAdLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ShortAdUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ShortAdUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ShortAdUpdate];
GO

CREATE PROCEDURE [proc_ShortAdUpdate]
(
	@ID int,
	@Content nvarchar(500) = NULL,
	@LastModifiedDate datetime = NULL,
	@Selected bit = NULL,
	@Deleted bit,
	@DealerOnly bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [ShortAd]
	SET
		[Content] = @Content,
		[LastModifiedDate] = @LastModifiedDate,
		[Selected] = @Selected,
		[Deleted] = @Deleted,
		[DealerOnly] = @DealerOnly
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ShortAdUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_ShortAdUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_ShortAdInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ShortAdInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ShortAdInsert];
GO

CREATE PROCEDURE [proc_ShortAdInsert]
(
	@ID int = NULL output,
	@Content nvarchar(500) = NULL,
	@LastModifiedDate datetime = NULL,
	@Selected bit = NULL,
	@Deleted bit,
	@DealerOnly bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [ShortAd]
	(
		[Content],
		[LastModifiedDate],
		[Selected],
		[Deleted],
		[DealerOnly]
	)
	VALUES
	(
		@Content,
		@LastModifiedDate,
		@Selected,
		@Deleted,
		@DealerOnly
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ShortAdInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_ShortAdInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_ShortAdDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_ShortAdDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_ShortAdDelete];
GO

CREATE PROCEDURE [proc_ShortAdDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [ShortAd]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_ShortAdDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_ShortAdDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SlideShowLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SlideShowLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SlideShowLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_SlideShowLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FileName],
		[Title],
		[Description],
		[URL],
		[Active]
	FROM [SlideShow]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SlideShowLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_SlideShowLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SlideShowLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SlideShowLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SlideShowLoadAll];
GO

CREATE PROCEDURE [proc_SlideShowLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[FileName],
		[Title],
		[Description],
		[URL],
		[Active]
	FROM [SlideShow]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SlideShowLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_SlideShowLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SlideShowUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SlideShowUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SlideShowUpdate];
GO

CREATE PROCEDURE [proc_SlideShowUpdate]
(
	@ID int,
	@FileName nvarchar(200),
	@Title nvarchar(500),
	@Description nvarchar(1000) = NULL,
	@URL nvarchar(500) = NULL,
	@Active bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [SlideShow]
	SET
		[FileName] = @FileName,
		[Title] = @Title,
		[Description] = @Description,
		[URL] = @URL,
		[Active] = @Active
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SlideShowUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_SlideShowUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_SlideShowInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SlideShowInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SlideShowInsert];
GO

CREATE PROCEDURE [proc_SlideShowInsert]
(
	@ID int = NULL output,
	@FileName nvarchar(200),
	@Title nvarchar(500),
	@Description nvarchar(1000) = NULL,
	@URL nvarchar(500) = NULL,
	@Active bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [SlideShow]
	(
		[FileName],
		[Title],
		[Description],
		[URL],
		[Active]
	)
	VALUES
	(
		@FileName,
		@Title,
		@Description,
		@URL,
		@Active
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SlideShowInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_SlideShowInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SlideShowDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SlideShowDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SlideShowDelete];
GO

CREATE PROCEDURE [proc_SlideShowDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [SlideShow]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SlideShowDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_SlideShowDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_StockLocationLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_StockLocationLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_StockLocationLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_StockLocationLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[LocationName],
		[Description],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [StockLocation]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_StockLocationLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_StockLocationLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_StockLocationLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_StockLocationLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_StockLocationLoadAll];
GO

CREATE PROCEDURE [proc_StockLocationLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[LocationName],
		[Description],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	FROM [StockLocation]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_StockLocationLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_StockLocationLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_StockLocationUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_StockLocationUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_StockLocationUpdate];
GO

CREATE PROCEDURE [proc_StockLocationUpdate]
(
	@ID int,
	@LocationName nvarchar(50) = NULL,
	@Description nvarchar(500) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [StockLocation]
	SET
		[LocationName] = @LocationName,
		[Description] = @Description,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_StockLocationUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_StockLocationUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_StockLocationInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_StockLocationInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_StockLocationInsert];
GO

CREATE PROCEDURE [proc_StockLocationInsert]
(
	@ID int = NULL output,
	@LocationName nvarchar(50) = NULL,
	@Description nvarchar(500) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [StockLocation]
	(
		[LocationName],
		[Description],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[BranchID]
	)
	VALUES
	(
		@LocationName,
		@Description,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_StockLocationInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_StockLocationInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_StockLocationDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_StockLocationDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_StockLocationDelete];
GO

CREATE PROCEDURE [proc_StockLocationDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [StockLocation]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_StockLocationDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_StockLocationDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_SuppliersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[SupplierName],
		[ABN],
		[Address],
		[Phone],
		[Fax],
		[Email],
		[AccountNo],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[TotalAmount],
		[PaidAmount],
		[BranchID]
	FROM [Suppliers]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersLoadAll];
GO

CREATE PROCEDURE [proc_SuppliersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[SupplierName],
		[ABN],
		[Address],
		[Phone],
		[Fax],
		[Email],
		[AccountNo],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[TotalAmount],
		[PaidAmount],
		[BranchID]
	FROM [Suppliers]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersUpdate];
GO

CREATE PROCEDURE [proc_SuppliersUpdate]
(
	@ID int,
	@SupplierName nvarchar(50) = NULL,
	@ABN nvarchar(20) = NULL,
	@Address nvarchar(100) = NULL,
	@Phone nvarchar(20) = NULL,
	@Fax nvarchar(20) = NULL,
	@Email nvarchar(20) = NULL,
	@AccountNo nvarchar(20) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@TotalAmount numeric(18,2) = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Suppliers]
	SET
		[SupplierName] = @SupplierName,
		[ABN] = @ABN,
		[Address] = @Address,
		[Phone] = @Phone,
		[Fax] = @Fax,
		[Email] = @Email,
		[AccountNo] = @AccountNo,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[TotalAmount] = @TotalAmount,
		[PaidAmount] = @PaidAmount,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_SuppliersInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersInsert];
GO

CREATE PROCEDURE [proc_SuppliersInsert]
(
	@ID int = NULL output,
	@SupplierName nvarchar(50) = NULL,
	@ABN nvarchar(20) = NULL,
	@Address nvarchar(100) = NULL,
	@Phone nvarchar(20) = NULL,
	@Fax nvarchar(20) = NULL,
	@Email nvarchar(20) = NULL,
	@AccountNo nvarchar(20) = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@TotalAmount numeric(18,2) = NULL,
	@PaidAmount numeric(18,2) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Suppliers]
	(
		[SupplierName],
		[ABN],
		[Address],
		[Phone],
		[Fax],
		[Email],
		[AccountNo],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[TotalAmount],
		[PaidAmount],
		[BranchID]
	)
	VALUES
	(
		@SupplierName,
		@ABN,
		@Address,
		@Phone,
		@Fax,
		@Email,
		@AccountNo,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@TotalAmount,
		@PaidAmount,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SuppliersDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SuppliersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SuppliersDelete];
GO

CREATE PROCEDURE [proc_SuppliersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Suppliers]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SuppliersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_SuppliersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SystemVariablesLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SystemVariablesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SystemVariablesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_SystemVariablesLoadByPrimaryKey]
(
	@Name nvarchar(50)
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Name],
		[Value],
		[Type],
		[Description]
	FROM [SystemVariables]
	WHERE
		([Name] = @Name)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SystemVariablesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_SystemVariablesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SystemVariablesLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SystemVariablesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SystemVariablesLoadAll];
GO

CREATE PROCEDURE [proc_SystemVariablesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[Name],
		[Value],
		[Type],
		[Description]
	FROM [SystemVariables]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SystemVariablesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_SystemVariablesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SystemVariablesUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SystemVariablesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SystemVariablesUpdate];
GO

CREATE PROCEDURE [proc_SystemVariablesUpdate]
(
	@Name nvarchar(50),
	@Value nvarchar(2000) = NULL,
	@Type nvarchar(50) = NULL,
	@Description nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [SystemVariables]
	SET
		[Value] = @Value,
		[Type] = @Type,
		[Description] = @Description
	WHERE
		[Name] = @Name


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SystemVariablesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_SystemVariablesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_SystemVariablesInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SystemVariablesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SystemVariablesInsert];
GO

CREATE PROCEDURE [proc_SystemVariablesInsert]
(
	@Name nvarchar(50),
	@Value nvarchar(2000) = NULL,
	@Type nvarchar(50) = NULL,
	@Description nvarchar(50) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [SystemVariables]
	(
		[Name],
		[Value],
		[Type],
		[Description]
	)
	VALUES
	(
		@Name,
		@Value,
		@Type,
		@Description
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SystemVariablesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_SystemVariablesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_SystemVariablesDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_SystemVariablesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_SystemVariablesDelete];
GO

CREATE PROCEDURE [proc_SystemVariablesDelete]
(
	@Name nvarchar(50)
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [SystemVariables]
	WHERE
		[Name] = @Name
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_SystemVariablesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_SystemVariablesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_TransferDetailsLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferDetailsLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferDetailsLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_TransferDetailsLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[TransferID],
		[ProductID],
		[IMEI],
		[Quantity]
	FROM [TransferDetails]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferDetailsLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferDetailsLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_TransferDetailsLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferDetailsLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferDetailsLoadAll];
GO

CREATE PROCEDURE [proc_TransferDetailsLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[TransferID],
		[ProductID],
		[IMEI],
		[Quantity]
	FROM [TransferDetails]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferDetailsLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferDetailsLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_TransferDetailsUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferDetailsUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferDetailsUpdate];
GO

CREATE PROCEDURE [proc_TransferDetailsUpdate]
(
	@ID int,
	@TransferID int,
	@ProductID int,
	@IMEI nvarchar(20) = NULL,
	@Quantity int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [TransferDetails]
	SET
		[TransferID] = @TransferID,
		[ProductID] = @ProductID,
		[IMEI] = @IMEI,
		[Quantity] = @Quantity
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferDetailsUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferDetailsUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_TransferDetailsInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferDetailsInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferDetailsInsert];
GO

CREATE PROCEDURE [proc_TransferDetailsInsert]
(
	@ID int = NULL output,
	@TransferID int,
	@ProductID int,
	@IMEI nvarchar(20) = NULL,
	@Quantity int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [TransferDetails]
	(
		[TransferID],
		[ProductID],
		[IMEI],
		[Quantity]
	)
	VALUES
	(
		@TransferID,
		@ProductID,
		@IMEI,
		@Quantity
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferDetailsInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferDetailsInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_TransferDetailsDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferDetailsDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferDetailsDelete];
GO

CREATE PROCEDURE [proc_TransferDetailsDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [TransferDetails]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferDetailsDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferDetailsDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_TransferHistoriesLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferHistoriesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferHistoriesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_TransferHistoriesLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[TransferedByUserID],
		[TransferedDate],
		[FromBranchID],
		[ToBranchID],
		[Description],
		[TransferNO]
	FROM [TransferHistories]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferHistoriesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferHistoriesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_TransferHistoriesLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferHistoriesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferHistoriesLoadAll];
GO

CREATE PROCEDURE [proc_TransferHistoriesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[TransferedByUserID],
		[TransferedDate],
		[FromBranchID],
		[ToBranchID],
		[Description],
		[TransferNO]
	FROM [TransferHistories]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferHistoriesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferHistoriesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_TransferHistoriesUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferHistoriesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferHistoriesUpdate];
GO

CREATE PROCEDURE [proc_TransferHistoriesUpdate]
(
	@ID int,
	@TransferedByUserID int = NULL,
	@TransferedDate datetime = NULL,
	@FromBranchID int = NULL,
	@ToBranchID int = NULL,
	@Description nvarchar(200) = NULL,
	@TransferNO char(10) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [TransferHistories]
	SET
		[TransferedByUserID] = @TransferedByUserID,
		[TransferedDate] = @TransferedDate,
		[FromBranchID] = @FromBranchID,
		[ToBranchID] = @ToBranchID,
		[Description] = @Description,
		[TransferNO] = @TransferNO
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferHistoriesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferHistoriesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_TransferHistoriesInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferHistoriesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferHistoriesInsert];
GO

CREATE PROCEDURE [proc_TransferHistoriesInsert]
(
	@ID int = NULL output,
	@TransferedByUserID int = NULL,
	@TransferedDate datetime = NULL,
	@FromBranchID int = NULL,
	@ToBranchID int = NULL,
	@Description nvarchar(200) = NULL,
	@TransferNO char(10) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [TransferHistories]
	(
		[TransferedByUserID],
		[TransferedDate],
		[FromBranchID],
		[ToBranchID],
		[Description],
		[TransferNO]
	)
	VALUES
	(
		@TransferedByUserID,
		@TransferedDate,
		@FromBranchID,
		@ToBranchID,
		@Description,
		@TransferNO
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferHistoriesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferHistoriesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_TransferHistoriesDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_TransferHistoriesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_TransferHistoriesDelete];
GO

CREATE PROCEDURE [proc_TransferHistoriesDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [TransferHistories]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_TransferHistoriesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_TransferHistoriesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_UsersLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_UsersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_UsersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_UsersLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[UserName],
		[FullName],
		[Password],
		[RoleID],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Address],
		[Phone],
		[BranchID]
	FROM [Users]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_UsersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_UsersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_UsersLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_UsersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_UsersLoadAll];
GO

CREATE PROCEDURE [proc_UsersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[UserName],
		[FullName],
		[Password],
		[RoleID],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Address],
		[Phone],
		[BranchID]
	FROM [Users]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_UsersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_UsersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_UsersUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_UsersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_UsersUpdate];
GO

CREATE PROCEDURE [proc_UsersUpdate]
(
	@ID int,
	@UserName nvarchar(50) = NULL,
	@FullName nvarchar(50) = NULL,
	@Password nvarchar(50) = NULL,
	@RoleID int = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Address nvarchar(100) = NULL,
	@Phone nvarchar(20) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Users]
	SET
		[UserName] = @UserName,
		[FullName] = @FullName,
		[Password] = @Password,
		[RoleID] = @RoleID,
		[Deleted] = @Deleted,
		[LastModifiedDate] = @LastModifiedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Address] = @Address,
		[Phone] = @Phone,
		[BranchID] = @BranchID
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_UsersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_UsersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_UsersInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_UsersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_UsersInsert];
GO

CREATE PROCEDURE [proc_UsersInsert]
(
	@ID int = NULL output,
	@UserName nvarchar(50) = NULL,
	@FullName nvarchar(50) = NULL,
	@Password nvarchar(50) = NULL,
	@RoleID int = NULL,
	@Deleted bit,
	@LastModifiedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Address nvarchar(100) = NULL,
	@Phone nvarchar(20) = NULL,
	@BranchID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [Users]
	(
		[UserName],
		[FullName],
		[Password],
		[RoleID],
		[Deleted],
		[LastModifiedDate],
		[LastModifiedByUser],
		[Address],
		[Phone],
		[BranchID]
	)
	VALUES
	(
		@UserName,
		@FullName,
		@Password,
		@RoleID,
		@Deleted,
		@LastModifiedDate,
		@LastModifiedByUser,
		@Address,
		@Phone,
		@BranchID
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_UsersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_UsersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_UsersDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_UsersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_UsersDelete];
GO

CREATE PROCEDURE [proc_UsersDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Users]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_UsersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_UsersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_VouchersLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VouchersLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VouchersLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_VouchersLoadByPrimaryKey]
(
	@ID uniqueidentifier
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Code],
		[SerieID],
		[IsUsed],
		[UsedByCustomerID],
		[UsedByCustomerName],
		[Active],
		[Deleted],
		[Balance]
	FROM [Vouchers]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VouchersLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_VouchersLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_VouchersLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VouchersLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VouchersLoadAll];
GO

CREATE PROCEDURE [proc_VouchersLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Code],
		[SerieID],
		[IsUsed],
		[UsedByCustomerID],
		[UsedByCustomerName],
		[Active],
		[Deleted],
		[Balance]
	FROM [Vouchers]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VouchersLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_VouchersLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_VouchersUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VouchersUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VouchersUpdate];
GO

CREATE PROCEDURE [proc_VouchersUpdate]
(
	@ID uniqueidentifier,
	@Code nvarchar(20),
	@SerieID uniqueidentifier,
	@IsUsed bit = NULL,
	@UsedByCustomerID int = NULL,
	@UsedByCustomerName nvarchar(100) = NULL,
	@Active bit,
	@Deleted bit,
	@Balance decimal(18,2) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [Vouchers]
	SET
		[Code] = @Code,
		[SerieID] = @SerieID,
		[IsUsed] = @IsUsed,
		[UsedByCustomerID] = @UsedByCustomerID,
		[UsedByCustomerName] = @UsedByCustomerName,
		[Active] = @Active,
		[Deleted] = @Deleted,
		[Balance] = @Balance
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VouchersUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_VouchersUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_VouchersInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VouchersInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VouchersInsert];
GO

CREATE PROCEDURE [proc_VouchersInsert]
(
	@ID uniqueidentifier,
	@Code nvarchar(20),
	@SerieID uniqueidentifier,
	@IsUsed bit = NULL,
	@UsedByCustomerID int = NULL,
	@UsedByCustomerName nvarchar(100) = NULL,
	@Active bit,
	@Deleted bit,
	@Balance decimal(18,2) = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int
	IF @ID IS NULL
		 SET @ID = NEWID()

	SET @Err = @@Error

	IF (@Err <> 0)
	    RETURN @Err


	INSERT
	INTO [Vouchers]
	(
		[ID],
		[Code],
		[SerieID],
		[IsUsed],
		[UsedByCustomerID],
		[UsedByCustomerName],
		[Active],
		[Deleted],
		[Balance]
	)
	VALUES
	(
		@ID,
		@Code,
		@SerieID,
		@IsUsed,
		@UsedByCustomerID,
		@UsedByCustomerName,
		@Active,
		@Deleted,
		@Balance
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VouchersInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_VouchersInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_VouchersDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VouchersDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VouchersDelete];
GO

CREATE PROCEDURE [proc_VouchersDelete]
(
	@ID uniqueidentifier
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [Vouchers]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VouchersDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_VouchersDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_VoucherSeriesLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VoucherSeriesLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VoucherSeriesLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_VoucherSeriesLoadByPrimaryKey]
(
	@ID uniqueidentifier
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Name],
		[ExpirationDate],
		[CreatedDate],
		[LastModifiedByUser],
		[Count],
		[DiscountPercent],
		[DiscountAmount],
		[Deleted],
		[MultiCheckOut]
	FROM [VoucherSeries]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VoucherSeriesLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_VoucherSeriesLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_VoucherSeriesLoadAll]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VoucherSeriesLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VoucherSeriesLoadAll];
GO

CREATE PROCEDURE [proc_VoucherSeriesLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[Name],
		[ExpirationDate],
		[CreatedDate],
		[LastModifiedByUser],
		[Count],
		[DiscountPercent],
		[DiscountAmount],
		[Deleted],
		[MultiCheckOut]
	FROM [VoucherSeries]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VoucherSeriesLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_VoucherSeriesLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_VoucherSeriesUpdate]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VoucherSeriesUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VoucherSeriesUpdate];
GO

CREATE PROCEDURE [proc_VoucherSeriesUpdate]
(
	@ID uniqueidentifier,
	@Name nvarchar(200) = NULL,
	@ExpirationDate datetime = NULL,
	@CreatedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Count int = NULL,
	@DiscountPercent int = NULL,
	@DiscountAmount decimal(18,2) = NULL,
	@Deleted bit,
	@MultiCheckOut bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [VoucherSeries]
	SET
		[Name] = @Name,
		[ExpirationDate] = @ExpirationDate,
		[CreatedDate] = @CreatedDate,
		[LastModifiedByUser] = @LastModifiedByUser,
		[Count] = @Count,
		[DiscountPercent] = @DiscountPercent,
		[DiscountAmount] = @DiscountAmount,
		[Deleted] = @Deleted,
		[MultiCheckOut] = @MultiCheckOut
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VoucherSeriesUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_VoucherSeriesUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_VoucherSeriesInsert]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VoucherSeriesInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VoucherSeriesInsert];
GO

CREATE PROCEDURE [proc_VoucherSeriesInsert]
(
	@ID uniqueidentifier,
	@Name nvarchar(200) = NULL,
	@ExpirationDate datetime = NULL,
	@CreatedDate datetime = NULL,
	@LastModifiedByUser int = NULL,
	@Count int = NULL,
	@DiscountPercent int = NULL,
	@DiscountAmount decimal(18,2) = NULL,
	@Deleted bit,
	@MultiCheckOut bit = NULL
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int
	IF @ID IS NULL
		 SET @ID = NEWID()

	SET @Err = @@Error

	IF (@Err <> 0)
	    RETURN @Err


	INSERT
	INTO [VoucherSeries]
	(
		[ID],
		[Name],
		[ExpirationDate],
		[CreatedDate],
		[LastModifiedByUser],
		[Count],
		[DiscountPercent],
		[DiscountAmount],
		[Deleted],
		[MultiCheckOut]
	)
	VALUES
	(
		@ID,
		@Name,
		@ExpirationDate,
		@CreatedDate,
		@LastModifiedByUser,
		@Count,
		@DiscountPercent,
		@DiscountAmount,
		@Deleted,
		@MultiCheckOut
	)

	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VoucherSeriesInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_VoucherSeriesInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_VoucherSeriesDelete]    Script Date: 9/17/2011 5:26:00 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_VoucherSeriesDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_VoucherSeriesDelete];
GO

CREATE PROCEDURE [proc_VoucherSeriesDelete]
(
	@ID uniqueidentifier
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [VoucherSeries]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_VoucherSeriesDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_VoucherSeriesDelete Error on Creation'
GO

/****** Object:  StoredProcedure [proc_WishListLoadByPrimaryKey]    Script Date: 9/17/2011 5:26:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_WishListLoadByPrimaryKey]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_WishListLoadByPrimaryKey];
GO

CREATE PROCEDURE [proc_WishListLoadByPrimaryKey]
(
	@ID int
)
AS
BEGIN
	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[CustomerID],
		[ProductID],
		[CreatedDate],
		[Deleted]
	FROM [WishList]
	WHERE
		([ID] = @ID)

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_WishListLoadByPrimaryKey Succeeded'
ELSE PRINT 'Procedure Creation: proc_WishListLoadByPrimaryKey Error on Creation'
GO

/****** Object:  StoredProcedure [proc_WishListLoadAll]    Script Date: 9/17/2011 5:26:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_WishListLoadAll]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_WishListLoadAll];
GO

CREATE PROCEDURE [proc_WishListLoadAll]
AS
BEGIN

	SET NOCOUNT ON
	DECLARE @Err int

	SELECT
		[ID],
		[CustomerID],
		[ProductID],
		[CreatedDate],
		[Deleted]
	FROM [WishList]

	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_WishListLoadAll Succeeded'
ELSE PRINT 'Procedure Creation: proc_WishListLoadAll Error on Creation'
GO

/****** Object:  StoredProcedure [proc_WishListUpdate]    Script Date: 9/17/2011 5:26:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_WishListUpdate]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_WishListUpdate];
GO

CREATE PROCEDURE [proc_WishListUpdate]
(
	@ID int,
	@CustomerID int,
	@ProductID int,
	@CreatedDate datetime = NULL,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	UPDATE [WishList]
	SET
		[CustomerID] = @CustomerID,
		[ProductID] = @ProductID,
		[CreatedDate] = @CreatedDate,
		[Deleted] = @Deleted
	WHERE
		[ID] = @ID


	SET @Err = @@Error


	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_WishListUpdate Succeeded'
ELSE PRINT 'Procedure Creation: proc_WishListUpdate Error on Creation'
GO




/****** Object:  StoredProcedure [proc_WishListInsert]    Script Date: 9/17/2011 5:26:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_WishListInsert]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_WishListInsert];
GO

CREATE PROCEDURE [proc_WishListInsert]
(
	@ID int = NULL output,
	@CustomerID int,
	@ProductID int,
	@CreatedDate datetime = NULL,
	@Deleted bit
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	INSERT
	INTO [WishList]
	(
		[CustomerID],
		[ProductID],
		[CreatedDate],
		[Deleted]
	)
	VALUES
	(
		@CustomerID,
		@ProductID,
		@CreatedDate,
		@Deleted
	)

	SET @Err = @@Error

	SELECT @ID = SCOPE_IDENTITY()

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_WishListInsert Succeeded'
ELSE PRINT 'Procedure Creation: proc_WishListInsert Error on Creation'
GO

/****** Object:  StoredProcedure [proc_WishListDelete]    Script Date: 9/17/2011 5:26:01 PM ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[proc_WishListDelete]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
    DROP PROCEDURE [proc_WishListDelete];
GO

CREATE PROCEDURE [proc_WishListDelete]
(
	@ID int
)
AS
BEGIN

	SET NOCOUNT OFF
	DECLARE @Err int

	DELETE
	FROM [WishList]
	WHERE
		[ID] = @ID
	SET @Err = @@Error

	RETURN @Err
END
GO


-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'Procedure Creation: proc_WishListDelete Succeeded'
ELSE PRINT 'Procedure Creation: proc_WishListDelete Error on Creation'
GO
